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 == '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
Use GitLab Pages to create a download page
See chapter Rules
Disable pipeline:
workflow:
rules:
- if: $CI_DEPLOY_FREEZE
when: never
- when: on_success
Template to disable job:
.freeze-deployment:
rules:
- if: $CI_DEPLOY_FREEZE
when: manual
allow_failure: true
- when: on_success
Rules not only control execution of jobs but can also configure jobs through the use of the following fields:
variables
to customize the behaviour of the jobchanges
on specific filesexists
needs
Rules become especially powerful when combining the fields supported by rules - including if
–
Pipelines can be skipped by adding [skip ci]
to the commit message
But GitLab still shows a skipped pipelines
Use a rule to avoid pipelines entirely:
my_job:
rules:
- if: $CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TITLE =~ /skip ci/i
when: never
Sometime the YAML parser gets confused
Use quotes to help the parser
workflow:
rules:
- if: '$VAR == "value"'
job_name:
rules:
- if: '$VAR2 == "value2"'
#...
The content directory can be configured using pages:publish
Premium/Ultimate: Deploy to a sub-directory pages:pages.path_prefix
Premium/Ultimate: Expire a pages deployment pages:pages.expire_in
GitLab Pages are public by default
Access control can be enabled