Jobs and stages

Jobs and stages

Jobs represent isolated steps in a pipeline

Stages are executed sequentially

Jobs in the same stage are executed in parallel

Described in .gitlab-ci.yml in YAML

Special stages .pre and .post

Job layout

Minimal job:

  - whoami
  - pwd
  - printenv | sort

script is a string and supports all herestring variants of YAML

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

Example code

Based on Go

See src/main.go

Build command: go build -o hello .


Use docker to play:

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

Dependency management

Initialize dependency information: go mod init

Update dependency information: go mod tidy


My first CI job

  1. Create project
  2. Add files from src/ to root of project
  3. Add build/.gitlab-ci.yml to root of project
  4. Check pipeline

My first stage

  1. Add lint/.gitlab-ci.yml to root of project
  2. Check pipeline

Parallel jobs

  1. Add parallel/.gitlab-ci.yml to root of project
  2. Check pipeline