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.

make a book

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 !!!

— Arthur
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.


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


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


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


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