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
# Register a self-managed runner (Docker executor)
gitlab-runner register --url https://gitlab.com \
--registration-token $TOKEN --executor docker --docker-image alpine:3Configuration reference
Stages, caching and a manual production gate.
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
# Validate and lint the pipeline before pushing
gitlab-ci-local --list
glab ci lintglab & runners
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 verifyRules & artifacts
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.
include:
- project: acme/ci-templates
file: /templates/node.yml
- template: Security/SAST.gitlab-ci.ymlBest-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.