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#:

  1. create a Dockerfile within Project A:
  2. run the pipleine of Project A
  3. expectation is that job will run, but does not

Reproduce 2#:

  1. create a Dockerfile within Project B
  2. remove the Dockerfile from Project A
  3. run the pipeline of Project A
  4. expectation is that job will 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

image

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

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.

Edited by Mark Nuzzo