Jobs and stages


Pipeline-as-Code

GitLab does not offer a visual pipeline editor

Pipelines are described in YAML

Pipelines are stored in .gitlab-ci.yml

YAML (YAML Ain’t Markup Language)

Human-readable data serialization format

  1. Fields:
  key: value
  1. Lists:
  key:
  - value1
  - value2
  1. Hash arrays:
  key:
    subkey1: value1
    subkey2: value2

YAML Example

# Commends are allowed
firstname: Nicholas
lastname: Dille
# Hash array keys are indented
# YAML usually uses two spaces for indentation
contact:
  email: you@wish.dev
  linkedin: https://www.linkedin.com/in/nicholasdille
  bsky: https://bsky.app/profile/nicholas.dille.name

# Empty lines are allowed
web:
- title: Blog
  link: https://dille.name
- title: GitHub
  link: https://github.com/nicholasdille
- title: GitLab
  link: https://gitlab.com/nicholasdille

# Array elements may be indented
# You must be consistent in one array
projects:
  - name: uniget
    homepage: https://uniget.dev
    code: https://gitlab.com/uniget-org

YAML to JSON

top:
- item1: value1
- item2:
    subitem1: value2
    subitem2: value3
- item3: value
  subitem1: value4
{
  "top:" [
    { "item1": "value1" },
    { "item2": { "subitem1": "value2", "subitem2": "value3" } },
    { "item3": "value", "subitem1": "value4" }
  ]
}

Tools for YAML/JSON

Jobs

Minimal job:

job_name:
  script: pwd

script can be a string but is mostly an array:

job_name:
  script:
  - pwd
  - whoami

Jobs fail if any command fails (exit code > 0)


Jobs with herestrings

script supports all herestring variants of YAML

Literal multiline block:

job_name:
  script:
  - |
    pwd
    whoami

Use this for commands with URLs or the colon will break parsing

Shell here documents:

job_name:
  script:
  - |
    tr a-z A-Z <<EOF
    lower case to be converted to upper case
    EOF

Jobs and stages

Jobs represent isolated steps in a pipeline

Stages are executed sequentially

Jobs in the same stage are executed in parallel

Special stages .pre and .post


Hands-On

See chapter Jobs and stages


Pro tip 1: Skip pipeline for push

Sometimes a pipeline run is not desirable

Option 1

Skip pipeline by adding [skip ci] in the commit message:

[skip ci] My awesome commit message
OR
My awesome commit message [skip ci]

Option 2

Leave commit message untouched

Provide a push option:

git push -o ci.skip

Pro tip 2: Pipeline Editor

The web UI offers a pipeline editor

Integrated syntax checking