In The Same File
We can extend GitLab rules
section with !reference [.hiddenjobname, section name]
. Here’s an example:
## Make sure that this specific pipeline is written
.publish-line-rules:
rules:
- if: '$CI_COMMIT_TAG == null && $CI_COMMIT_REF_PROTECTED == "true"'
Publisher (Tag):
stage: deploy
image: registry.gitlab.com/chez14/publisher:v1.0.2
rules:
- !reference [.publish-line-rules, rules] ## HERE IT IS!
needs:
- "Test"
script:
- setup-git.sh
- gitlab-unshallow.sh
- taggedVersion="v$(autotag)"
- echo VERSION=$taggedVersion >> taginfo.env
- git push --tags
artifacts:
reports:
# To ensure we've access to this file in the next stage
dotenv: taginfo.env
Reasons:
- Because of the spec, “There’s no way of merging sequences on YAML level.“.
https://stackoverflow.com/a/4949139/4721245
Resources:
- Forum Discussion:
https://forum.gitlab.com/t/extend-job-rules-with-multiple-reference-containing-array-of-rules/70190/2?u=chez14 - Suggested by SO peeps:
https://stackoverflow.com/a/69768241/4721245 - Official Documentation:
https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags
In Template File (via include:
keyword)
Have not yet tried x.x
TODO: Try to do this.