GitLab CI/CD 1 cheatsheet

GitLab CI/CD 1: Pipeline basics

6 common GitLab CI/CD 1 tasks.

Minimal pipeline

A .gitlab-ci.yml with three stages. Jobs in the same stage run in parallel.

stages:
  - build
  - test
  - deploy

build-job:
  stage: build
  script:
    - echo "Building"

test-job:
  stage: test
  script:
    - echo "Testing"

Choose a Docker image

Run a job in a container image.

test-job:
  image: node:24
  script:
    - npm ci
    - npm test

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.

variables:
  NODE_ENV: production

build-job:
  variables:
    LOG_LEVEL: debug

Run setup and cleanup commands

Run commands before and after a job's script.

test-job:
  before_script:
    - npm ci
  script:
    - npm test
  after_script:
    - echo "Done"

Pick a runner by tag

Run the job only on runners that have the tag.

build-job:
  tags:
    - docker

Set a timeout and retries

Fail a job that runs too long, and retry it automatically on infrastructure failures.

flaky-job:
  timeout: 15 minutes
  retry:
    max: 2
    when: runner_system_failure

Was this page helpful?