Add project/file options to exists rules
What does this MR do and why?
- Adds the ability to define
project
andfile
keys within anexists
rule in a CI config. Designed for use within theinclude:rules
, it'll work anywhere you can useexists
. - Before, you could only check if files existed within the same project. This change adds the ability to check for the existence of file in a different project.
- The main reason behind this change was to stop errors from occuring when starting a pipeline on a project that did not have its own CI config but was subject to a compliance pipeline but it could have other legitimate uses too.
- This is a non-breaking change. The 'before' example below will still function as before.
Before
include:
- local: do_this_if_max_exists.yml
rules:
- exists:
- max.md
After
include:
- local: do_this_if_max_exists.yml
rules:
- exists:
- project: "example-group/example-project-1"
file: "max.md"
- Variables are also valid here too. An example that we will give in the docs for compliance pipelines relies on this.
-
ref
is not supported yet. It will also refer to the default branch of the target project.
include:
project: '$CI_PROJECT_PATH'
file: '$CI_CONFIG_PATH'
ref: '$CI_COMMIT_REF_NAME'
rules:
- exists:
- project: '$CI_PROJECT_PATH'
file: '$CI_CONFIG_PATH'
Screenshots or screen recordings
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
- Set up a series of projects with different CI configurations that make use of the exists keywords: https://docs.gitlab.com/ee/ci/yaml/#rulesexists
- Assert that they function as before.
- Alter the same project to use the explicit
project
andfile
keywords as described above. - Assert that the function the same as before.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #332040 (closed)
Edited by Dan Jensen