>_ IzzyLab

Hands-on task

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

GitLab CI: inheritance via extends

medium~15 min

The project app (cloned to /root/app, the web sign-in is on the GitLab tab) has a green pipeline, but .gitlab-ci.yml is copy-pasted: the lint and test jobs set the same variables and before_script.

Move what they share into a hidden template job .base (with variables and before_script), and let lint and test inherit it via extends, keeping only stage and script of their own. Push to main: the pipeline must stay green. Open .gitlab-ci.yml in the Editor tab, and look at the resulting config after extends in GitLab: Build → Pipeline editor → Full configuration.

What you'll practise:
  • gitlab ci
  • extends
  • job templates
  • inheritance
  • yaml

Topic breakdown

extends in GitLab CI reuses a job's configuration without copy-paste: the child job takes all of the parent's fields and can override some with its own. Maps (variables, for example) are merged recursively, but same-named lists (script or before_script, for example) are not appended — they're fully replaced by the child job's value. Templates are usually hidden from running: a job whose name starts with a dot is not treated by GitLab as real and isn't added to the pipeline on its own — it's a template meant purely for extends.

What's checked

  1. A .base template with variables and before_script
  2. lint and test inherit .base without copy-paste
  3. Latest pipeline on main is green
  4. The lint job passed
  5. The test job passed

What it looks like