Rules define whether to execute a job
At least one successful rule for the job to be executed
job_name:
rules:
- if: $VAR == "value"
- if: $VAR2 = "value2"
#...
Formerly only
/except
which are “not actively developed”
Official documentation of job control
Workflow rules define whether to execute a whole pipeline
workflow:
rules:
- if: $VAR == "value"
- if: $VAR2 = "value2"
job_name:
#...
Conditions are also used in workflow rules
Disable execution for some trigger types
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'push'
- if: $CI_PIPELINE_SOURCE == 'web'
- if: $CI_PIPELINE_SOURCE == 'schedule'
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
- if: $CI_PIPELINE_SOURCE == 'pipeline'
- if: $CI_PIPELINE_SOURCE == 'api'
when: never
- if: $CI_PIPELINE_SOURCE == 'trigger'
when: never
Rules are evaluated in-order
First match determines result
Adjust order from most specific…
…to most general
Disable pipeline:
workflow:
rules:
- if: '$CI_DEPLOY_FREEZE'
when: manual
- when: on_success
Template to disable job:
.freeze-deployment:
rules:
- if: '$CI_DEPLOY_FREEZE'
when: manual
allow_failure: true
- when: on_success
See chapter Rules