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
6stages: [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
6rules: [{ 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: manualRequire human approval
when: delayed, start_in: 5 minutesWait before running
Artifacts & Caching
4artifacts: { 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
4glab ci runCreate a pipeline run
glab ci statusLatest pipeline status
glab ci trace JOB_IDLive job log
glab ci viewWatch a pipeline live