Reputation: 584
I have many rules in my CI config, and also many anchors.
It's not an offence to the linter to mention rules:
multiple times per job, but the same linter does not help with testing whether multiple rules:
clauses add up and in which order.
So the trouble is, now I have to repeat the slightly changing set of rules in every job.
.build-rules: &build-rules
rules:
- if: '$DEPLOY_TAG'
when: never
- if: '$CI_COMMIT_REF_NAME == "master"'
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_COMMIT_REF_NAME =~ "/^v[0-9]+\.[0-9]+.*$/"'
job_with_changed_rule:
<<: *build-rules
rules:
- if: '$DEPLOY_TAG'
script:
- do something
job_with_another_rule:
<<: *build-rules
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
script:
- do something else
Upvotes: 4
Views: 12591
Reputation: 41
Before Gitlab 14.3 the only thing you could do was placing extends
block
But now you can re-use rules from other jobs with !reference
tag.
For more details see this docs
Upvotes: 4