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


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:
  - |
    multi
    line

Shell here documents:

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

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 src/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:

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


Hands-On

Follow in web UI or IDE

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

Add a stage

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

Add parallel jobs

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