GitLab CI Cheatsheet
Top patterns.
Overview
The GitLab CI cheatsheet captures the patterns operators actually use, not the full keyword reference. Five primitives cover almost every pipeline a team writes: stages, jobs, rules, needs, and includes.
- Stages, jobs, rules. Stages run sequentially; jobs within a stage run in parallel; rules decide whether each job runs.
- rules over only/except.
rules:is the modern syntax.only:andexcept:are legacy and should not appear in new pipelines. - needs for DAG.
needs:declares job-level dependencies and skips stage gates where the dependency graph allows. Pipelines run faster. - include and cache.
include:reuses pipeline definitions across repos;cache:persistsnode_modulesor.m2between runs.
The approach
Three habits separate a fluent GitLab CI user from a tutorial-driven one: rules over only/except, needs for parallelism, and include for organisational reuse.
- rules: in every job. Every job carries a
rules:block. The conditions are explicit; the “why does this run on master?” question disappears. - needs: for DAG. Where independent jobs sit in different stages, declare the dependency and let the rest run in parallel. Pipeline duration drops.
- include: for reuse. Per-team or per-org pipeline templates live in one repo and every other repo includes them. Conventions scale.
- cache: for build artefacts. Persist heavy directories between runs. Cold caches are an order of magnitude slower than warm ones.
Why this compounds
GitLab CI fluency is high-leverage because the same primitives serve every pipeline the team writes. Each captured pattern reuses across repos.
- Faster pipelines. needs-based DAG cuts pipeline wall-clock time materially on any non-trivial graph.
- Cross-repo reuse. include captures conventions in one place. New repos inherit the standard pipeline rather than copying YAML.
- Faster builds. Right caching produces fast builds. Developer experience improves visibly within a sprint.
- Year-one investment, year-two habit. The first pipeline takes effort. By the tenth, the patterns are reflexive and the YAML reads cleanly.