Tool cheatsheet
GitLab CI/CD 1 Cheatsheet
.gitlab-ci.yml snippets for stages, jobs, rules, caching, artifacts, services, environments and reuse.
Pipeline basics
- Minimal pipeline — A .gitlab-ci.yml with three stages. Jobs in the same stage run in parallel.
- Choose a Docker image — Run a job in a container image.
- Define variables — Set variables for the whole pipeline or for one job. Store secrets in the project's CI/CD settings, not in this file.
- Run setup and cleanup commands — Run commands before and after a job's script.
- Pick a runner by tag — Run the job only on runners that have the tag.
- Set a timeout and retries — Fail a job that runs too long, and retry it automatically on infrastructure failures.
When jobs run
- Run only on the default branch — Use rules to control when a job is added to the pipeline.
- Run for merge requests — Run a job in merge request pipelines.
- Run only when files change — Run a job only if matching files changed.
- Require a manual click — Add a play button so a person starts the job.
- Allow a job to fail — Let the pipeline pass even if this job fails.
- Avoid duplicate pipelines — Run branch pipelines only when there is no open merge request.
- Run only on a schedule — Run a job only in scheduled pipelines, which you configure under Build, Pipeline schedules.
Caching, artifacts and ordering
- Cache dependencies — Reuse downloaded packages between pipelines. The key changes when the lock file does.
- Pass files to later jobs — Keep build output so later jobs and people can download it.
- Start a job as soon as dependencies finish — Skip waiting for the whole previous stage.
- Run a job for several versions — Create one job per variable combination.
- Start a database for tests — Run a service container beside the job.
- Show test results in merge requests — Upload a JUnit report so failures show up in the merge request.
Deploy and reuse
- Deploy to an environment — Track deployments and their URL in GitLab.
- Prevent concurrent deployments — Make deploy jobs run one at a time.
- Build a Docker image — Build and push to the project's registry, using the predefined CI variables.
- Share job settings — Define a hidden template job, and reuse it with extends.
- Include other files — Include a template or a shared file from another project.
- Trigger a downstream pipeline — Start a pipeline in another project.
- Useful predefined variables — Common variables GitLab sets for every job.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.