Thanks for this post - I had this exact same question. The docs for rules say
You can use
!referencetags to reuserulesconfiguration in different jobs.
But and when I click through to reuse rules configuration, I see this example:
.default_rules:
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
job1:
rules:
- !reference [.default_rules, rules]
script:
- echo "This job runs for the default branch, but not schedules."
job2:
rules:
- !reference [.default_rules, rules]
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- echo "This job runs for the default branch, but not schedules."
- echo "It also runs for merge requests."
Putting this in the pipeline editor results in:
".default_rules":
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
job1:
rules:
- - if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
script:
- echo "This job runs for the default branch, but not schedules."
job2:
rules:
- - if: $CI_PIPELINE_SOURCE == "schedule"
when: never
- if: "$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH"
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- echo "This job runs for the default branch, but not schedules."
- echo "It also runs for merge requests."
I don’t find any place saying how rules supports nested arrays, so the expected behavior here is ambiguous. I’d like to request that the docs be updated. What is the expected behavior?