Skip to content

Support CI config `include:rules:changes`

Leaminn Ma requested to merge ci-support-includes-rules-changes into master

What does this MR do and why?

This MR adds support for rules:changes (including the subkeys paths and compare_to) to include:rules.

Main changes:

  • The Entry::Include::Rules::Rule class is augmented with the changes entry.
  • The pipeline object is passed into Config::External::Context as it is required to evaluate the changes clause.
  • Refactored and updated spec/lib/gitlab/ci/config/external/processor_spec.rb.

Feature flag: ci_support_include_rules_changes

  • When the FF is off, the changes: keyword is still permitted but it has no effect.

FF Roll-out issue: #421608 (closed)

Resolves the final step (Step 2) of #342209 (closed).

How to set up and validate locally

  1. Enable the feature flag: Feature.enable(:ci_support_include_rules_changes)
  2. In your project root, create 4 files with the following content (replace X with an integer 1-4):

File name: configX.yml

Content:

jobX:
  script: echo
  1. Create another file named test.txt with 0 in its content.
  2. Update your .gitlab-ci.yml with the following:
include:
  - local: config1.yml
    rules:
      - if: $VAR == null # true
        changes:
          - test.txt
        when: never
      - exists:
          - config1.yml # true
  - local: config2.yml
    rules:
      - if: $VAR == null # true
        changes:
          - test.txt
  - local: config3.yml
    rules:
      - if: $VAR == 'true' # false
        changes:
          - test.txt
  - local: config4.yml
    rules:
      - changes:
          paths:
            - test.txt
          compare_to: 'main'
  1. Create a new branch named branch1 from main.
  2. On branch1, update the content of the README.md file (or any file other than test.txt) and commit.
  3. View the latest pipeline for branch1, it should only have job1:

Screenshot_2023-08-22_at_5.46.44_PM

  1. On branch1, update the content of test.txt to 1 and commit.
  2. View the latest pipeline for branch1, it should have job2 and job4:

Screenshot_2023-08-22_at_5.54.22_PM

  1. Create a new branch named branch2 from branch1.
  2. On branch2, update the content of test.txt to 2 and commit.
  3. View the latest pipeline for branch2, it should have job2 and job4:

Screenshot_2023-08-22_at_5.54.22_PM

  1. On branch2, update the content of test.txt to 0 and commit.
  2. View the latest pipeline for branch2, it should only have job2:

Screenshot_2023-08-22_at_5.48.25_PM

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 #342209 (closed)

Edited by Leaminn Ma

Merge request reports

Loading