← All insightsCheat Sheet

GitLab CI/CD cheat sheet: the complete command reference

CodeWizard Engineering · 27 June 2026 · 3 min read · Beginner

This is a complete, hands-on GitLab CI/CD cheat sheet: install, configure, operate, automate and secure it - with copy-paste commands grouped by task. Bookmark it for day-to-day work, incidents and interviews alike.

GitLab CI/CD runs pipelines defined in .gitlab-ci.yml on GitLab Runners, with stages, jobs, environments and built-in DevSecOps scanning - all in one platform next to the repo.

Why you reach for it

  • One platform for SCM, CI/CD, registry and security scanning
  • Pipelines-as-code with reusable includes and templates
  • Built-in environments, review apps and manual deploy gates

Installation

bash
# Register a self-managed runner (Docker executor)
gitlab-runner register --url https://gitlab.com \
  --registration-token $TOKEN --executor docker --docker-image alpine:3

Configuration reference

Stages, caching and a manual production gate.

yaml
stages: [build, test, deploy]
cache: { paths: [node_modules/] }

build:
  stage: build
  image: node:20
  script: [npm ci, npm run build]

test:
  stage: test
  image: node:20
  script: [npm test]

deploy:prod:
  stage: deploy
  script: [./deploy.sh]
  environment: { name: production }
  when: manual
  rules: [{ if: '$CI_COMMIT_BRANCH == "main"' }]

Core commands you use daily

bash
# Validate and lint the pipeline before pushing
gitlab-ci-local --list
glab ci lint

glab & runners

bash
glab ci lint
glab ci run --branch main
glab ci view
gitlab-runner register --url https://gitlab.com --executor docker
gitlab-runner list && gitlab-runner verify

Rules & artifacts

yaml
rules:
  - if: '$CI_COMMIT_BRANCH == "main"'
    when: on_success
artifacts:
  paths: [dist/]
  expire_in: 1 week
  reports: { junit: report.xml }

Use it in CI/CD

Reuse shared pipeline logic with include.

yaml
include:
  - project: acme/ci-templates
    file: /templates/node.yml
  - template: Security/SAST.gitlab-ci.yml

Best-practice checklist

  • Use stages and needs: for a fast DAG pipeline
  • Cache dependencies and pass build output as artifacts
  • Store secrets as masked, protected CI/CD variables

Common pitfalls to avoid

  • Everything in one stage, so nothing runs in parallel
  • No cache/artifacts config, re-downloading dependencies every job
  • Secrets in .gitlab-ci.yml instead of masked/protected CI variables

Security quick wins

  • Enable built-in SAST, dependency and container scanning templates
  • Mark secret variables masked+protected and scope them to protected branches

Works well with

  • GitHub Actions - CI/CD built into GitHub - event-driven workflows defined in YAML, with a huge marketplace of actions.
  • Jenkins - The extensible automation server for CI/CD, with pipelines defined as code in a Jenkinsfile.
  • Trivy - A fast, all-in-one scanner for container images, filesystems, IaC and Kubernetes.
A cheat sheet is muscle memory on paper - keep it close until the commands live in your fingers.

Want senior help putting GitLab CI/CD to work - or a team bootcamp on it? CodeWizard runs Israel's largest DevOps community and embeds named senior engineers with a transparent hours log. Book a free consult or explore the Academy.

Like where this is going?

Get hands-on help from the engineers who write these posts.

Book a free consult