>_ IzzyLab

Hands-on task

This task is step 4 of the course “CI/CD: pipelines and docker compose”

GitLab CI: two stages

medium~15 min

The project app (cloned to /root/app, the web sign-in is on the GitLab tab) has an app.py module with tests, but no CI. A runner is already connected to the project.

Write a .gitlab-ci.yml with two stages: build, then test, and one job per stage. The build stage's job checks that the code compiles: python3 -m py_compile app.py. The test stage's job runs the tests: python3 -m unittest -v.

Push to main and get a green pipeline. In the GitLab web UI, watch the stages run one after another.

What you'll practise:
  • gitlab ci
  • stages
  • yaml pipeline
  • job and script
  • stage order
  • pipeline

Topic breakdown

GitLab CI describes a pipeline with a single YAML file, where the stages: key sets the list of stages specifically in execution order: the next stage starts only after all the jobs of the previous one succeed. Unlike GitHub Actions, each job here is a separate top-level key of the file (not nested under jobs:), which has a stage: with a stage name from the list and a script: with a list of commands. The typical pitfalls — referencing a non-existent stage in stage: or messing up the indentation of the nested map.

What's checked

  1. .gitlab-ci.yml is in main
  2. Two stages: build, then test
  3. Latest pipeline on main is green
  4. The build stage job passed
  5. The test stage job ran the tests

What it looks like