Skip to content

Add project/file options to exists rules

Max Woolf requested to merge mw/support-for-file-project-in-exists-ci into master

What does this MR do and why?

  • Adds the ability to define project and file keys within an exists rule in a CI config. Designed for use within the include:rules, it'll work anywhere you can use exists.
  • 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 and file 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.

Related to #332040 (closed)

Edited by Dan Jensen

Merge request reports

Loading