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
Run the deploy
job only for the main
branch
public
in repositorypublic/
to new folder public
.gitlab-ci.yml
See new .gitlab-ci.yml
:
git checkout origin/160_gitlab_ci/130_rules -- '*'
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
Pipelines often have many jobs
Rules will be repeated multiple times
Combine rules with templates to prevent repetition
.rule-only-web:
rules:
- if: $CI_PIPELINE_SOURCE == 'web'
job_name:
extends:
- .rule-only-web
#...
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