Setting Up a GitLab Pipeline
July 27, 2019I have been slowly exploring the free tier of gitlab and today wanted to setup a build in the CI
job. The following steps are taken to create a build of a static site via jekyll.
Create .gitlab-ci.yml
touch .gitlab-ci.yml
Edit the file
As with any build script I simply put the steps I ran locally and placed them into the yml
file.
image: "ruby:2.5"
build:
script:
- cd ./site/ && bundle install
- bundle exec jekyll build
- zip -r site-build.zip ./_site
note, unlike circleci each script execution will persist directory structure, e.g. cd site
now puts you in the site
folder for any proceeding script items.
The first Error
$ zip -r site-build.zip ./_site
/bin/bash: line 90: zip: command not found
It appears our image does not contain, zip
so we will need to install it via a before_script
block.
image: "ruby:2.5"
before_script:
- apt-get install -y p7zip
build:
script:
- cd ./site/ && bundle install
- ls
- bundle exec jekyll build
- zip -r site-build.zip ./_site
Another Error
root@item:/# apt-get install p7zip
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package p7zip
I learned that since this is a fresh image you also need to run the update
command first.
image: "ruby:2.5"
before_script:
- apt-get update -qy
- apt-get -y install zip unzip
Don't forget to add in -y
to auto answer the prompt.
The final build yml
file
image: "ruby:2.5"
before_script:
- apt-get update -qy
- apt-get -y install zip unzip
build:
script:
- cd ./site/ && bundle install
- bundle exec jekyll build
- zip -r site-build.zip ./_site
Artifacts
Now we have all of your pieces in order and our build is successful next up getting an artifact of the build which happens to be the rendered site from jekyll
.
Storing the contents of the zip as an artifact
artifacts:
name: "viking-mill"
paths:
- ./site/site-build.zip
expire_in: 30 days
note, this new block will reset to the root working folder so you need to specify the full path from the root
The Final .gitlab-ci.yml
image: "ruby:2.5"
before_script:
- apt-get update -qy
- apt-get -y install zip unzip
build:
script:
- cd ./site/ && bundle install
- bundle exec jekyll build
- zip -r site-build.zip ./_site
artifacts:
name: "viking-mill"
paths:
- ./site/site-build.zip
expire_in: 30 days
Finish
Now we have a build setup inside of gitlab for the static jekyll site
Cover image credit: http://facebook.com/RodrigoMoraesPhotography