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
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
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
#...