Problem to solve
I want to include a file based on rules specified through yaml anchors. The goal of doing this is to organize workflows with reusable rules to improve readability and maintainability.
- What are you seeing, and how does that differ from what you expect to see?
The rules with yaml anchors works correctly when $CI_PIPELINE_SOURCE
is push
, but not when it is merge_request_event
.
Configuration
Add the CI/CD configuration from .gitlab-ci.yml
and other configuration if relevant (e.g. docker-compose.yml). Alternatively, create a public GitLab.com example project that provides all necessary files to reproduce the question.
Created a public repository with MVCE (minimum verifiable complete example) here: Aravind Pai / honeycomb · GitLab
- Please see the file
main.yml
in branchinclude-with-rules
: .gitlab-ci/include-with-rules/main.yml · include-with-rules · Aravind Pai / honeycomb · GitLab (main.yml
is included from the project root’s.gitlab-ci.yml
) - The merge request is created here: Draft: demo include with rules (!1) · Merge requests · Aravind Pai / honeycomb · GitLab
- On
push
event, the pipeline job is run as expected here: Pipeline · Aravind Pai / honeycomb · GitLab
- On
merge_request_event
, the pipeline job runs, but the expected job is not included: Pipeline · Aravind Pai / honeycomb · GitLab
Here is the main.yml
file for convenient reference:
.push_to_default_branch: &push_to_default_branch
- if: $CI_PIPELINE_SOURCE == "push"
.merge_request_to_default_branch: &merge_request_to_default_branch
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
print-env:
stage: demo
rules:
- when: always
script:
- export
include:
# note: commenting out the push-job below also doesn't
# lead to the `merge-request-job` being included
- local: .gitlab-ci/include-with-rules/push-job.yml
rules:
- *push_to_default_branch
# end note
- local: .gitlab-ci/include-with-rules/merge-request-job.yml
rules:
- *merge_request_to_default_branch
I cannot for the life of me figure out why the include
with rules
behaves differently between push
and merge_request_event
.
What have I missed here?
Versions
Please select whether options apply, and add the version information.
- Self-managed
- GitLab.com SaaS
- Self-hosted Runners
Versions
- GitLab (Web:
/help
or self-managed system information): Web - GitLab Runner, if self-hosted (Web
/admin/runners
or CLIgitlab-runner --version
): Web