100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

GitLab CI/CD Cheat Sheet

GitLab CI/CD Cheat Sheet

Reference for .gitlab-ci.yml syntax, stages, jobs, rules, and caching for GitLab's built-in CI/CD pipelines.

2 PagesIntermediateFeb 15, 2026

Basic Pipeline

Minimal .gitlab-ci.yml with build, test, deploy stages.

yaml
stages:  - build  - test  - deploybuild-job:  stage: build  script:    - echo "Building..."    - make buildtest-job:  stage: test  script:    - make testdeploy-job:  stage: deploy  script:    - make deploy  rules:    - if: '$CI_COMMIT_BRANCH == "main"'

Rules & Caching

Conditional execution and dependency caching.

yaml
test-job:  stage: test  cache:    key: ${CI_COMMIT_REF_SLUG}    paths:      - node_modules/  script:    - npm ci    - npm test  rules:    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'      when: always    - when: never

Predefined Variables

Common CI/CD variables available in every job.

  • CI_COMMIT_SHA- Full SHA of the commit being built
  • CI_COMMIT_REF_SLUG- URL/DNS-safe slug of the branch or tag name
  • CI_PIPELINE_SOURCE- What triggered the pipeline (push, merge_request_event, schedule, etc.)
  • CI_JOB_TOKEN- Token scoped to the job for authenticating to GitLab APIs/registries
  • CI_PROJECT_DIR- Absolute path where the repository is checked out in the job
  • CI_ENVIRONMENT_NAME- Name of the environment associated with a deployment job

Artifacts & Docker-in-Docker

Passing artifacts between stages and building images.

yaml
build-image:  stage: build  image: docker:24  services:    - docker:24-dind  script:    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA  artifacts:    paths:      - dist/    expire_in: 1 week
Pro Tip

Use 'extends' with hidden jobs (prefixed with a dot, e.g. .base_job) to DRY up repeated configuration across similar jobs instead of copy-pasting script blocks.

Was this cheat sheet helpful?

Explore Topics

#GitLabCICD#GitLabCICDCheatSheet#DevOps#Intermediate#BasicPipeline#RulesCaching#PredefinedVariables#ArtifactsDockerInDocker#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet