Backend: Conditional includes evaluated incorrectly when using exists rules
Summary
If Project A includes a CI File from Project B which has a conditional include, the include is not evaluated against Project A but Project B.
Although the expectation is, that the include exists is evaluated against Project A - to allow more general purpose and self-managed includes without additional setup logic.
Steps to reproduce
Basic Setup:
- Project A .gitlab-ci.yml
# project A
include:
- project: ProjectB
file: include.yml
- Project B include.yml
include:
- local: sub-include.yml
rules:
- exists:
- "Dockerfile"
- Project B sub-include.yml
# actually not relevant
job:
script: echo "test"
Reproduce 1#:
- create a Dockerfile within Project A:
- run the pipleine of Project A
- expectation is that
jobwill run, but does not
Reproduce 2#:
- create a Dockerfile within Project B
- remove the Dockerfile from Project A
- run the pipeline of Project A
- expectation is that
jobwill run, and it does, although there is no Dockerfile within the project which is triggering the CI pipeline
Example Project
Project with the includes: https://gitlab.com/lazy-lint/my-project
Project using the includes: https://gitlab.com/lazy-lint/testing/bigtestproject
- should run a HadoLint step and a Go step and a CSS step, based on the files, but does not do so
What is the current bug behavior?
Conditional includes for file existence are evaluated in the context of the project we are including the file from, if the condition is defined within that project.
What is the expected correct behavior?
Conditional includes for file existence should be evaluated against the files of the project which is including the files even if those are sub includes from a different project.
Relevant logs and/or screenshots
As you can see the jobs are created based on the file existence in the Project i am included the file from, instead of the project where the pipeline is started.
Output of checks
This bug happens on GitLab.com
Additional customer context
- We are trying to use the "exists" rule to conditionally include, when a docker-compose.yml file is found in a repo, a template that adds the DIND service and necessary variables to the pipeline. Without this, we end up including the DIND service on every job, which is a waste of resources for many jobs.
Additional links
- see #341511 (comment 782819207) for the initial discussion
- https://gitlab.com/gitlab-com/account-management/eastern-north-america/granular/-/issues/30#note_1130469947 - customer use case with additional details
User Impact
With the inability for users to reference an include defined in Project A in Project B, this creates more complexity between sharing variables, etc.
