Support `variables` for workflow `rules`
This is a follow-up issue from #209864 (closed).
Copied from that issue:
Release notes
Previously, the rules
keyword was limited in scope and only determined if a job should be included or excluded from pipelines. Lately we've added the ability to override variables in a job, In this release, we've extended this ability so you can now decide if certain conditions are met and subsequently override pipeline variables, providing you with more flexibility when configuring your pipelines.
Problem to solve
Rules define when certain jobs can be run, but they could also provide overrides for configuration. This would be a handy way to set up rules for when certain policies or variables should be set. One example use case would be making cache-policy settable by “rules” to say for example that you only want to update the cache pull-push on master and not on branches. Another could be setting interruptible
using various rules.
Intended users
Proposal
In this issue, we only add variables
to the workflow rules
.
Add variables
to rules to specify variables. To use the example from the problem to solve section, this would look like:
workflow:
variables:
MY_VAR: "initial value"
rules:
- if: $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
variables:
MY_VAR: "hello"
job1:
variables:
DEPLOY_VARIABLE: "job1-default-deploy"
rules:
- if: $CI_COMMIT_REF_NAME =~ /master/
variables: # Override DEPLOY_VARIABLE defined
DEPLOY_VARIABLE: "job1-deploy-production" # at the job level.
- when: on_success # Run the job in other cases
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.