GitLab CI/CD Zeger-Jan van de Weg
GitLab CI/CDZeger-Jan van de Weg
Today...
● What is CI/CD
● GitLab CI/CD
○ Setting up your first pipeline!
● Questions
What is CI/CD
● Continuous Integration / Continuous Deployment○ Short iterations○ Fast feedback○ Quick improvements
● To do this, you need to automate the process○ Run tests○ Run a deploy job
● GitLab has an integrated CI solution! :)
Setup
● GitLab Runner○ Executors
■ SSH■ Docker■ Docker auto-scaled
○ Platforms■ Linux■ Mac■ Windows
Setup
● Shared vs Specific○ Shared
■ Might be limited to tags■ Should be enabled for your project
● Settings > Runners > Enable Shared runners● Specific
○ Only for 1 project○ No need to enable
● Install guide
Setup GitLab
● Job definitions are in the git repo○ .gitlab-ci.yml
● For this lecture I assume a Docker executor○ Most environment agnostic○ Each job should be idempotent, SSH doesn’t provide this
My first .gitlab-ci.yml
image "ubuntu:xenial"
test:
script:
- cat file1.txt file2.txt | grep -q "Hello world"
My first .gitlab-ci.yml
image "ruby:2.1"
test:
script:
- cat file1.txt file2.txt | grep -q "Hello world"
My first .gitlab-ci.yml
My first .gitlab-ci.yml
My second .gitlab-ci.yml
image "ruby:2.1"
test:
script:
- cat file1.txt file2.txt | grep -q "Hello world"
package:
script:
- cat file1.txt file2.txt | gzip > package.gz
My second .gitlab-ci.yml
My second .gitlab-ci.yml
package:
artifacts:
paths:
- package.gz
script:
- cat file1.txt file2.txt | gzip > package.gz
My second .gitlab-ci.yml
Sequential builds
stages: - test - package
test: stage: test script: cat file1.txt file2.txt | grep -q 'Hello world'
package: stage: package script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
Sequential builds
stages: - test - package
test: stage: test script: cat file1.txt file2.txt | grep -q 'Hello world'
package: stage: package script: cat file1.txt file2.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
My second .gitlab-ci.yml
stages: - compile - test - package
compile: stage: compile script: cat file1.txt file2.txt > compiled.txt artifacts: paths: - compiled.txt
test: stage: test script: cat compiled.txt | grep -q 'Hello world'
package: stage: package script: cat compiled.txt | gzip > packaged.gz artifacts: paths: - packaged.gz
My second .gitlab-ci.yml
My second .gitlab-ci.yml
● Caching○ Like artifacts but used for dependencies
■ node_modules■ npm install■ Without cache, build should still run successfully
My second .gitlab-ci.yml
● Small demo :)
My second .gitlab-ci.yml
● Further reading:○ GitLab CI Docs○ GitLab Runner Docs
● Question?○ Ask now!○ @ZJvandeWeg○ [email protected]