Skip to content

Add project ref name in pipeline variables service

Rajendra Kadam requested to merge 430786-ci-var-commit-ref-name into master

What does this MR do and why?

Adds ref in call to YamlProcessor in Ci::ListConfigVariablesService.

By doing this, it fixes the bug in #430786 (closed) and #438593 (closed)

Note: This change is behind a feature flag project_ref_name_in_variables (#466427 (closed)).

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

NA

How to set up and validate locally

  1. This needs a runner setup in your local gdk.
  2. Setup runner using docker setup.
  3. Use the following CI yaml content spread across 3 files.
.gitlab-ci.yml
include:
  - local: 'include1.yml'
    rules:
      - if: $CI_COMMIT_REF_NAME =~ /master/
  - local: 'include2.yml'
    rules:
      - if: $CI_COMMIT_REF_NAME !~ /master/
include1.yml
variables:
  VAR1:
    description: 'VAR1 from include1 YAML file'
    value: 'var1'
  COMMON_VAR:
    description: 'Common variable'
    value: 'include1'

JOB1:
  script:
    - echo $VAR1
    - echo $VAR2
    - echo $COMMON_VAR
include2.yml
variables:
  VAR2:
    description: 'VAR2 from include2 YAML file'
    value: 'var2'
  COMMON_VAR:
    description: 'Common variable'
    value: 'include2'

JOB2:
  script:
    - echo $VAR1
    - echo $VAR2
    - echo $COMMON_VAR
  1. For master branch or whatever your main branch is, you should see the following variables.

Screenshot_2024-06-10_at_3.27.17_PM

  1. If any other than the main branch, you should see the following variables.

Screenshot_2024-06-11_at_3.07.43_PM

Related to #430786 (closed)

Edited by Rajendra Kadam

Merge request reports