GitLab CI/CD 1 cheatsheet
GitLab CI/CD 1: When jobs run
7 common GitLab CI/CD 1 tasks.
Run only on the default branch
Use rules to control when a job is added to the pipeline.
deploy-job:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
Run for merge requests
Run a job in merge request pipelines.
test-job:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
Run only when files change
Run a job only if matching files changed.
build-docs:
rules:
- changes:
- docs/**/*
Require a manual click
Add a play button so a person starts the job.
deploy-prod:
when: manual
script:
- ./deploy.sh
Allow a job to fail
Let the pipeline pass even if this job fails.
lint-job:
allow_failure: true
script:
- npm run lint
Avoid duplicate pipelines
Run branch pipelines only when there is no open merge request.
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH
Run only on a schedule
Run a job only in scheduled pipelines, which you configure under Build, Pipeline schedules.
nightly-job:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"