>_ IzzyLab

Hands-on task

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

GitLab CI: include an external file

medium~15 min

The project app (cloned to /root/app, the web sign-in is on the GitLab tab) has a red pipeline on main: the test job can't find the built dist/. The build is described by the team's shared template templates/build.yml (a build job with an artifact), but it isn't included in .gitlab-ci.yml.

Include /templates/build.yml in .gitlab-ci.yml via include (the local type). Don't copy the template itself, and don't describe the build job in .gitlab-ci.yml. Push to main and get a green pipeline.

What you'll practise:
  • gitlab ci
  • include
  • local
  • modular configuration
  • yaml

Topic breakdown

include assembles the final pipeline config from several files: the included file is expanded as if its contents were pasted verbatim in place of the include, and all its jobs, templates, and variables become part of the overall config. The source is set by the element's key: local — a file in the same repository, project — from another project, remote — at an HTTP(S) URL, template — GitLab's ready-made templates. include: is always a list; the path for local is given from the repository root, and the file must actually exist at the right ref, otherwise the pipeline fails before the jobs even start.

What's checked

  1. include local /templates/build.yml
  2. build isn't copied into .gitlab-ci.yml
  3. Latest pipeline on main is green
  4. The build job in the build stage passed
  5. The test job in the test stage passed

What it looks like