CI rules parameter hard to generalize across jobs
Problem to solve
GitLab 12.3 introduced the rules parameter, which can be used in lieu of only/except. I'm trying to use this in order to take advantage of rules:exists (introduced in GitLab 12.4). But, I'm finding the syntax impossible to generalize across multiple jobs with extends.
Here is a simplified example configuration before rules. Here, I have only/when
conditions defined in a skipped job named .dev_conditions
, which is extended by 3 concrete jobs named Plan
, Apply
, and Destroy
, varying in when they're run.
.dev_conditions:
only:
refs:
- branches
variables:
- $DEPLOYMENT_ENVIRONMENTS =~ /\bdev\b/
except:
refs:
- master
Plan:
extends:
- .tf_plan
- .dev_conditions
when: always
Apply:
extends:
- .tf_apply
- .dev_conditions
when: on_success
Destroy:
extends:
- .tf_destroy
- .dev_conditions
when: manual
If I modify .dev_conditions
to use the rules
parameter instead of only/except
, there's no easy way for me to vary the when
parameter. I'd have to copy the conditions to each job.
.dev_conditions:
rules:
- if: …
when: always
- when: never
Plan:
extends:
- .tf_plan
- .dev_conditions
Apply:
extends:
- .tf_apply
- .dev_conditions
# How to set when: on-success without copying the entire rules list?
Destroy:
extends:
- .tf_destroy
- .dev_conditions
# How to set when: manual without copying the entire rules list?
Intended users
Further details
Jobs like Apply
and Destroy
extend .dev_conditions
. But, because rules
is a list, I can't override just the when
parameter of any particular rule. I have to redefine the entire rules
list.
Note: Since keywords like branches
aren't supported in rules
, this particular example isn't implementable using rules, regardless of whether when
can be overridden.
Proposal
I'd like both the basic when parameter and the when attribute in rules to accept variables instead of just literal values. Then, a variable could be used for the when
attribute in .dev_conditions
, with the value provided by the jobs extending it.
Permissions and Security
N/A
Documentation
N/A
Testing
N/A
What does success look like, and how can we measure that?
Be able to convert from existing only/except parameters to rules and easily change the when attribute of rules without repeating entire rules lists.
What is the type of buyer?
Rules is part of Core.