Jobs and stages


GitLab does not offer a visual pipeline editor

Pipelines are described in YAML

Pipelines are stored in .gitlab-ci.yml


Minimal job:

  script: pwd

script can be a string but is mostly an array:

  - pwd
  - whoami

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

Jobs with herestrings

script supports all herestring variants of YAML

Literal multiline block:

  - |

Shell here documents:

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

Testing job scripts

Script blocks can be testing using a container based on alpine:

docker run -it --rm -v $PWD:/src -w /src alpine sh

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

Example code

Based on Go

See main.go

Initialize dependency information: go mod init

Update dependency information: go mod tidy

Build command: go build -o hello .

Playground for experts

Use docker to play:

docker run --interactive --tty --rm \
    --volume ${PWD}:/project --workdir /project \
    golang bash

Hands-On (1)

First CI job

  1. Create project
  2. Add files to root of project:

     git checkout origin/160_gitlab_ci/010_jobs_and_stages/build -- '*'

  3. Check pipeline

Hands-On (2)

Add a stage

  1. Add lint/.gitlab-ci.yml to root of project:

     git checkout origin/160_gitlab_ci/010_jobs_and_stages/lint -- '*'

  2. Check pipeline

Hands-On (3)

Add parallel jobs

  1. Add parallel/.gitlab-ci.yml to root of project:

     git checkout origin/160_gitlab_ci/010_jobs_and_stages/parallel -- '*'

  2. Check pipeline

Pro tip: Skip pipeline for push

Sometimes a pipeline run is not desirable

Option 1

Skip pipeline by prefixing the commit message:

[skip ci] My awesome commit message

Option 2

Leave commit message untouched

Provide a push option:

git push -o ci.skip