You are on page 1of 7

GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

 Kitchen, Audio 
e.g., Regular Expressions, Garden,   

LOGIN or REGISTER

 Home  Cheat Sheets  Create  Community  Help

 Download This Cheat Sheet (PDF)  Comments Rating:      (0) 

Home > Cheat Sheets > Cicd Cheat Sheets

GitLab CI/CD Pipeline Configuration Cheat Sheet (DRAFT) by


violaken

GitLab CI/CD Pipeline Configuration YAML Examples

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Pipeline Architecture Jobs Management Flow Control

Globals | Includes | Before/After | Stages | Parameters | Environments Rules | Retries


Extends
Stages rules Evaluation
Global Defaults
stages: docker build:
default image | services | before-
  - .pre   script: docker build -t my-image:$SLUG
_script | after_script |   - build   rules:

cache   - test     - changes:


  - deploy       - Dockerfile
variables Cannot be specified   - .post       when: manual

under default     - if: '$VAR == "string value"'


      when: manual
stages Cannot be specified .pre and .post stages are guaranteed     - when: on_success

under default to be the first (.pre) or last (.post)


docker build:
stage in a pipeline
Job values always override global   script: docker build -t my-image:$SLUG
  rules:
defaults.
Disabling Jobs by Hiding Them     - if: '$VAR == "string value"'
      changes:
      - Dockerfile
.hidden_job:       - docker/scripts/*
  script:       when: manual
    - run test

To conjoin if and changes clauses


temporarily ‘disable’ a job by
with an AND, use them in the same
prepending a dot (.)
rule.

1 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Include Variables Job Retries

include: variables: test:


  - remote: 'https://gitlab.com/awesome-project/raw/ma
  ENVIRONMENT: "staging"   script: rspec
  - local: '/templates/.after-script-template.yml'
  DB_URL: "postgres://postgres@postgres/db  retry:
  - template: Auto-DevOps.gitlab-ci.yml     max: 2
  - project: 'my-group/my-project' build:     when:
    ref: master   script: mvn build       - runner_system_failure
    file: '/templates/.gitlab-ci-template.yml'
  variables:       - stuck_or_timeout_failure
    ENVIRONMENT: "production"

extension: .yml | .yaml when: always | unknown_failure |


script_failure | api_failure |
Environment stuck_or_timeout_failure | runner-
Before and After Scripts _system_failure | missing_depende-
ncy_failure | runner_unsupported
review_app:
default:   stage: deploy
  before_script:   script: make deploy-app Interruptible
    - global before script   environment:
    name: review
job: stages:
    on_stop: stop_review_app
  before_script:   - stage1

    - execute this instead of global   - stage2


stop_review_app:
  script:   stage: deploy
    - my command step-1:
  variables:
  after_script:   stage: stage1
    GIT_STRATEGY: none
    - execute this after my script   script:
  script: make delete-app
    - echo "Can be canceled"
  when: manual
  
  environment:
step-2:
    name: review
Extends   stage: stage2
    action: stop
  script:
    - echo "Can not be canceled"
.only-important: deploy as review app:
  interruptible: false
  only:   stage: deploy

    - master   script: make deploy

    - stable   environment:


This value will only be used if the
  tags: name: review/$CI_COMMIT_REF_NAME
automatic
    url: https://$CI_ENVIRONMENT_SLUG.example.com/ cancellation of
    - production
redundant pipelines feature is
.in-docker: enabled.
  tags:
Pages
    - docker
  image: alpine
pages:
rspec:   stage: deploy
  extends:   script:
    - .only-important     - mkdir .public
    - .in-docker     - cp -r * .public
  script:     - mv .public public
    - rake rspec   artifacts:
    paths:
spinach:       - public
  extends: .in-docker   only:
  script: rake spinach     - master

Pages is a special job that is used to


upload static content to GitLab that
can be used to serve your website

2 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Dependencies Protecting Manual Jobs

build:osx: deploy_prod:
  stage: build   stage: deploy
  script: make build:osx   script:
  artifacts:     - echo "Deploy to production server"
    paths:   environment:
      - binaries/     name: production
    url: https://example.com
build:linux:   when: manual
  stage: build   only:
  script: make build:linux     - master
  artifacts:   allow_failure: false
    paths:
      - binaries/
In the protected environments
test:osx: settings, select the environment and
  stage: test
add the users, roles or groups that
  script: make test:osx
  dependencies: are authorized to trigger the manual
    - build:osx job to the Allowed to Deploy list

test:linux:
  stage: test Artifact Management
  script: make test:linux
  dependencies: Artifacts | Docker | Cache
    - build:linux

Artifacts
deploy:
  stage: deploy
  script: make deploy job:
  artifacts:
    name: "$CI_JOB_NAME"
By default, all artifacts from all
    paths:
previous stages are passed to the       - binaries/

current job, but you can use the       - .config


    untracked: true
dependencies parameter to define a
    when: on_failure
limited list of jobs (or no jobs) to     expire_in: 1 week

fetch artifacts from.


code_quality:
  stage: test
  script: codequality /code
  artifacts:
    reports:
      codequality: gl-code-quality-report.json
  coverage: '/Code coverage: \d+\.\d+/'

untracked: true | false


when: on_success | on_failure |
always | manual

Docker Image

image:
  name: super/sql:experimental
  entrypoint: [""]

3 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Needs Docker Service

linux:build: services:
  stage: build   - name: postgres:9.4
    alias: db
mac:build:     entrypoint: ["docker-entrypoint.sh"
  stage: build     command: ["postgres"]

linux:rspec:
  stage: test
  needs: ["linux:build"]
Cache

linux:rubocop:
build:
  stage: test
  script: mvn test
  needs: ["linux:build"]
  cache:
    key: build
mac:rspec:
    untracked: true
  stage: test
    paths:
  needs: ["mac:build"]
      - binaries/
    policy: pull
mac:rubocop:
  stage: test
  needs: ["mac:build"] policy : pull | push | pull-push

untracked : true | false


production:
  stage: deploy

The needs: keyword enables


executing jobs out-of-order, allowing
you to implement a directed acyclic
graph. This lets you run some jobs
without waiting for other ones,
disregarding stage ordering so you
can have multiple stages running
concurrently.

4 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Tags

job:
  tags:
    - ruby
    - postgres

osx job:
  stage:
    - build
  tags:
    - osx
  script:
    - echo "Hello, $USER!"

tags is used to select specific


Runners from the list of all Runners
that are allowed to run this project.
During the registration of a Runner,
you can specify the Runner’s tags,
for example ruby, postgres, windows,
osx.

Trigger

staging:
  stage: deploy
  trigger: my/deployment

staging-branch:
  stage: deploy
  trigger:
    project: my/deployment
    branch: stable

trigger allows you to define


downstream pipeline trigger. When a
job created from trigger definition is
started by GitLab, a downstream
pipeline gets created.

5 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Parallel

test:
  parallel: 3
  script:
    - bundle
    - bundle exec rspec_booster --job

parallel allows you to configure how


many instances of a job to run in
parallel. This value has to be greater
than or equal to two (2) and less
than or equal to 50.

 gitlab  pipeline  yaml  cicd

Download the GitLab CI/CD

Pipeline Configuration Cheat Sheet

PDF (recommended)

 PDF (4 pages)

Alternative Downloads

 PDF (black and white)


 LaTeX

4 Pages

6 of 7 1/6/23, 08:16
GitLab CI/CD Pipeline Configuration Cheat Sheet by vio... https://cheatography.com/violaken/cheat-sheets/gitlab-ci...

Latest Cheat Sheet Random Cheat Sheet

Pathfinder 2nd VI Editor Cheat


Edition: Conditions Sheet
Cheat Sheet VI Editor shortcuts and modes.

A short cheat sheet of all the ericg


conditions listed in the Pathfinder  24 Feb 12, updated 25 Feb 20
2E Core Rulebook  development, linux,
 3 Pages  2 Pages commandline, beginner, vi and 2
sophicandle
more ...
     (0)  6 Jan 23      (44)
 pathfinder

About Cheatography Behind the Scenes Recent Activity


Cheatography is a collection of 5578 If you have any problems, or just want sophicandle published
cheat sheets and quick references in to say hi, you can find us right here: Pathfinder 2nd Edition:
25 languages for everything from Conditions.
DaveChild
French to google! 3 hours 2 mins ago

roman_balzer published VS
SpaceDuck
Code Keybinds.
8 hours 39 mins ago
Cheatography
sams sub updated divorce.
21 hours 7 mins ago

© 2011 - 2023 Cheatography.com | CC License | Terms | Privacy  Latest Cheat Sheets RSS Feed

7 of 7 1/6/23, 08:16

You might also like