Add support for `when: never` on conditional includes
What does this MR do and why?
This MR adds support for when: never
on conditional includes.
The file is not included into the pipeline if:
- If no rules match.
- If a rule matches and has
when: never
If there are no rules, the file is included as expected. Also note that when: null
behaves the same as not specifying when:
.
Feature flag: ci_support_include_rules_when_never
Implementation:
- Step 1: This MR
- Step 2: Add support for `when: always` on conditional i... (!123443 - merged)
Resolves #348146 (closed).
How to set up and validate locally
- Add two config files to your project root:
config1.yml
:
job1:
script: echo
config2.yml
:
job2:
script: echo
- Prior to turning on the Feature Flag, first observe that the
when:
value does not have any effect. Update your.gitlab-ci.yml
file with the following content and run the pipeline.
include:
- local: config1.yml
rules:
- if: $VAR == null
when: never
- local: config2.yml
rules:
- if: $VAR == null
when: never
job0:
script: echo
All 3 jobs are included in the pipeline.
- Turn on the Feature Flag:
Feature.enable(:ci_support_include_rules_when_never)
. - Re-run the pipeline and observe that only the base
job0
is present.
- Test the following config. Observe that the rule precedence is followed (first matching rule takes effect) and the
when:
value works as expected. Onlyjob0
andjob2
should be present in the pipeline.
include:
- local: config1.yml
rules:
- if: $VAR == null
when: never
- if: $VAR == null
- local: config2.yml
rules:
- if: $VAR != null
when: never
- exists:
- non-existing.yml
- if: $VAR == null
job0:
script: echo
Also note that when:
works with the exists
condition as well. Example:
include:
- local: config1.yml
rules:
- exists:
- config1.yml
when: never
- if: $VAR == null
- local: config2.yml
rules:
- if: $VAR != null
when: never
- exists:
- non-existing.yml
- exists:
- config1.yml
job0:
script: echo
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #348146 (closed)
Edited by Leaminn Ma