Stages
Covered Gitlab features : stages
Now that basics have no secret for you, Perceval (You) and Karadoc decided to make a book with all the more iconic quotes from Kaamelott city. This book will be a gift for the King Arthur.
On y voit comme à travers une pelle là-dedans… Hé lumières !!! Pff bande de fainéants… Ah ça, pour roupiller, vous êtes fortiche (s’esclaffe) Les chevaliers de la Table Ronde… CHEVALIERS DE MES DEUX !!! Chuis p… chuis pas roi, moi ? C’est p…, c’est pas moi le roi ?! (dégainant Excalibur) Et ça, c’est du nougat ??? Tout seul, je vais le chercher le Graal, moi, et la vie éternelle, c’est pour bibi !!! Et vous, vous irez vous gratter !!!
Kaamelott S01E18
Use default stage
📝 Instructions
The book will be represented by the following Kotlin program : https://gitlab.com/gitlab-workshop/kaamelott-quote
➡️ Work in your previous created project
➡️ Remove src
folder
➡️ Download the kaamelott-quote
project using this link
➡️ Copy all kaamelott-quote
project files at the root (overwrite all if needed)
Be sure to copy hidden files too (prefixed by a dot) |
➡️ Erase content of .gitlab-ci.yml
file
➡️ Add a global before_script
block in the .gitlab-ci.yml
file which executes the following script : chmod +x mvnw
➡️ Add a first job named build
using the openjdk:8-jdk-slim
image and executes the ./mvnw --batch-mode install -DskipTests
script
➡️ Add another job named unit tests
which also use the openjdk:8-jdk-slim
image and executes the ./mvnw --batch-mode test
script
➡️ Use git to commit and push your modifications :
git add .
git commit -m "chore(ci): add build and test jobs"
git push
➡️ Follow your job execution and note changes
You could see that Gtilab C.I have automatically created a stage (named Test ) and placed your two jobs inside it.
|
Your jobs are executed in parallel because they are in the same stage. |
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/1948b7b6fc45a4307878b1173ee5a8210479906a/ // REF(stages:default)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275965668 // REF(stages:default)
Split into distinct stages
📝 Instructions
Now, you would like to execute tests only after build job was successful.
➡️ Rename the unit tests
job to unit
➡️ Edit your .gitlab-ci.yml
and specify the build
stage for your build
job and test
stage in your unit
job
➡️ Use git to commit and push your modifications :
git add .
git commit -m "chore(ci): separate jobs in distinct stages"
git push
➡️ Follow your job execution and note that your jobs are executed one after the other
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/39709fe3a457f45171e11aa487270993cc2cbceb/ // REF(stages:split)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275965810 // REF(stages:split)
Run in parallel
Your application builds and executes tests, great ! But it would be nice if e2e tests will be played with unit tests.
📝 Instructions
➡️ Add another job named e2e tests
which also use the openjdk:8-jdk-slim
image and executes the ./mvnw --batch-mode test -Dtests.tags="e2e"
script
➡️ Add the test
stage to the new created job
➡️ Use git to commit and push your modifications :
git add .
git commit -m "chore(ci): add e2e tests in parallel"
git push
➡️ Follow your job execution and note that unit/e2e tests are now executed in parallel once the build is successful
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/89a6edf8e84073edbdd0038f3fb5a6d09c14841d/ // REF(stages:parallel)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275965939 // REF(stages:parallel)
Change execution order
We would now change the execution order and play test
stage before build
stage.
📝 Instructions
➡️ Add the following content at the beginning of your .gitlab-ci.yml
file :
stages:
- test
- build
➡️ Use git to commit and push your modifications :
git add .
git commit -m "chore(ci): execute tests before build"
git push
➡️ Follow your pipeline execution using :
https://gitlab.com/gitlab-workshop/swiss-institute-of-bioinformatics/<your-project>/pipelines
Test jobs are now executed before the build job |
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/5fd786b62d31f3673f0731bb73ca31200079f88f/ // REF(stages:order)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275966050 // REF(stages:order)
Customize stage name
📝 Instructions
➡️ Work in your previous created project
➡️ Work in a new branch using git checkout -b rename-test-stage
➡️ Replace test
stage by tests
in your .gitlab-ci.yml
file like following :
stages:
- tests
- build
unit:
stage: tests
...
e2e tests:
stage: tests
➡️ Use git to commit and push your modifications :
git add .
git commit -m "chore(ci): rename test stage"
git push -u origin rename-test-stage
➡️ Follow your job execution and note changes
You can also add your own custom stages if you want |
🚨 Solution
Project : https://gitlab.com/gitlab-workshop/solutions/blob/6958f07eb54afb1587d9f99aeb7bd1f6f8e49805/ // REF(stages:custom)
Pipeline : https://gitlab.com/gitlab-workshop/solutions/pipelines/275966187 // REF(stages:custom)