GitLab CI: Use `!reference` to Extend Rules

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:

Resources:

In Template File (via include: keyword)

Have not yet tried x.x

TODO: Try to do this.

Disclaimer:

Not all articles here are meant to be correct. My notes might be wrong or may no longer be relevant. If you want to try things here, please proceed with caution.


Posted

in

,

by