Search code examples
gitlab-cigitlab-ci.ymlgitlab-ci-trigger

Why is the global variable taking precedence over the project variables?


I am trying to understand why my pipeline ends up using the global variable value instead of the one I defined at the project level. My understanding was that project variables take precedence over global ones.

.gitlab-ci.yml

variables:
  REGION: '"null"' # this value ends up being used

include:
  - local: header.yml

stages:
  - validate

Create Test:
  stage: validate
  variables:
    SUBDOMAIN: e2e-sn-$CI_PIPELINE_ID
  trigger:
    include: integration_test.yml
    strategy: depend
    forward:
      pipeline_variables: true
  rules:
    - if: $RUN_E2E_INTEGRATION_TESTS == "true"
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
      variables:
        RESTART_TEST: 'true'
      when: manual
      changes:
        - 'venom/e2e/**/*'

header.yml

.e2e:
  rules:
    - if: $CI_PIPELINE_SOURCE == "parent_pipeline"

.venomE2E:
  variables: 
    VENOM_VAR_region: $REGION
    VENOM_VAR_subdomain: $SUBDOMAIN
  extends:
    - .e2e

integration_test.yml

include:
  - local: header.yml

stages:
  - Create

Create site:
  stage: Create
  extends: .venomE2E
  script:
    - venom run e2e/create.yaml

I have 'REGION' defined as a project variable so I was expecting "VENOM_VAR_region" to contain it's value. However, it instead has the global variable's value


Solution

  • As it is written in the docs, trigger variables have the highest precedence.

    In your example you are using trigger.forward.pipeline_variables: true setting, which makes REGION a trigger variable and therefore its precedence becomes the highest. This behavior is also described in the docs.