Support `variables` for workflow `rules`
This is a follow-up issue from #209864 (closed).
Copied from that issue:
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.
In this issue, we only add
variables to the workflow
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