Gitlab pipeline fundamentals

This article goes through some of the fundamentals of GitLab pipelines to help getting started. It assumes prior knowledge of CI/CD and focuses on the GitLab specifics.

What does the extends keyword do?

The extends keywords enables a configuration section in a GitLab pipeline YAML to be re-used in other sections.

Example:

stages:
  - build_john
  - build_jane

.echo_name
  script:
    - |
      echo "Hello $NAME"      

build_john:
  extends:
    - .echo_name
  variables:
    NAME: John

build_jane:
  extends:
    - .echo_name
  variables:
    NAME: Jane

Official documentation

What is the include section for?

The include section on a GitLab pipeline includes a configuration file on a pipeline. It facilitates pipeline reusability by providing a mechanism to source other locations.

It can include scripts from the local project:

include:
  - 'templates/.after-script-template.yml'

From a internet location:

include:
  - 'https://gitlab.com/awesome-project/raw/main/.before-script-template.yml'

Or from another GitLab project:

include:
  - project: 'my-group/my-project'
    ref: main
    file: 'templates/.gitlab-ci-template.yml'

Official documentation