Skip to content

Backend: include:rules:exists acts differently than <job>:rules:exists

Summary

rules:exists acts differently when used in an include section vs job definition

  • When used in a job definition, rules:exists checks for file existence in the GitLab project where the job is running.
  • When used in an include, rules:exists checks for the file existence in the GitLab project where the yml file containing the 'include:rules:exists' clause.

My expectation is that both rules:exists would check for existence in the GitLab project where the pipeline is running.

Steps to reproduce

  • Create repo one add the following:
  • test.txt (just a file, content not important)
  • Add gitlab-ci.yml
stages:
- test
job-from-local:
  stage: test
  script:
  - echo "This job rule on file exists in pipeline repo from pipeline repo"
  rules:
    - exists:
      - test.txt

include:
  - project: "ruskel/test-rule-exists-two"
    ref: main
    file: "include_rule.yml"
  - project: "ruskel/test-rule-exists-two"
    ref: main
    file: "job_rule.yml"
  • Create repo two and add the following:
  • test2.txt (just a file, content not important)
  • create include_rule.yml
include:
- project: "ruskel/test-rule-exists-two"
  ref: main
  file: "test_task.yml"
  rules:
    - exists:
      - test.txt
- project: "ruskel/test-rule-exists-two"
  ref: main
  file: "test2_task.yml"
  rules:
    - exists:
      - test2.txt
  • Create job_rule.yml
job-from-pipeline:
  stage: test
  script:
  - echo "This job rule on file exists in pipeline repo"
  rules:
    - exists:
      - test.txt

job-from-include:
  stage: test
  script:
  - echo "This job rule on file exists in include file repo"
  rules:
    - exists:
      - test2.txt
  • Create test_task.yml
include-from-pipeline:
  stage: test
  script:
  - echo "This include rule on file exists in pipeline repo"
  • Create test2_task.yml
include-from-include:
  stage: test
  script:
  - echo "This include rule on file exists in included repo"
  • Run the pipeline from repo one
  • See the output where include-from-include and job-from-pipeline are executed

Example Project

What is the current bug behavior?

the include:rules:exists uses the files in the repo where the yaml that defines the include resides but job:rules:exists uses the files in the repo where the pipeline is executed

What is the expected correct behavior?

I would like to see both execute the rules:exists against the repo where the pipeline is executed. The use case for this is a custom 'testing.yml' file in a library that developers can include. This single include decides what actual implementation yml files should be included based on the repo configuration (ie pom.xml indicates maven testing implementation is required).

Proposal

Support paths, project and ref subkeys with rules:exists. The paths syntax should align with how paths are used in rules:changes.

Usage:

include:
  - local: hello.yml
    rules:
      exists:
        paths: [abc.md, cd.md]
        project: root/my-project
        ref: main

job:
  script: exit 0
  rules:
    exists:
      paths: [xyz.yml]
      project: root/my-project
      ref: main

As part of this issue, update the documentation to clarify that the default context of job:rules:exists is the pipeline project. The default context of include:rules:exists is the project in which the include is defined.

Security requirement

Ensure that the user has access privileges to the project specified in exists:project

Implementation Table

Group Issue Link
documentation #346960 (closed)
backend 👈 You are here
Edited by Leaminn Ma