GitLab CI Cheat Sheet

The .gitlab-ci.yml reference — stages, jobs, rules, and the glab CLI for enormous runners and pipelines.

CI/CD4 sections · 20 commands
⌘K

File Structure

6
stages: [build, test, deploy]

Declare the pipeline stages

build: { stage: build, script: ['go build'] }

A minimal job

default: { image: node:20 }

Default image for all jobs

variables: { DEPLOY_TARGET: prod }

Pipeline-wide variables

include: [{ local: '.ci/ci-common.yml' }]

Reuse configs from other files

pages: { stage: deploy, script: [...], artifacts: { paths: ['public'] } }

Publish GitLab Pages

Rules & Conditions

6
rules: [{ if: '$CI_PIPELINE_SOURCE == "merge_request_event"' }]

Only on MRs

rules: [{ if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main"' }]

Target branch condition

rules: [{ if: '$CI_COMMIT_TAG' }]

Only on tagged releases

rules: [{ changes: ['src/**/*'] }]

Run when files change

when: manual

Require human approval

when: delayed, start_in: 5 minutes

Wait before running

Artifacts & Caching

4
artifacts: { paths: ['dist/'] }

Pass files between jobs

artifacts: { expire_in: '1 week' }

Auto-expire downloads

cache: { key: '$CI_JOB_NAME', paths: ['node_modules/'] }

Cache dependencies

artifacts: { reports: { coverage: [...] } }

Parse coverage reports

glab CLI

4
glab ci run

Create a pipeline run

glab ci status

Latest pipeline status

glab ci trace JOB_ID

Live job log

glab ci view

Watch a pipeline live