The project defined variable is not taking precedence over the hardcoded variable

Summary

A variable with the same name is defined at both project variables and in .gitlab-ci.yml file at the same time. As per this documentation, the variables defined at the project level should take precedence over the .gitlab-ci.yml file.

However, the customer has a variable called AWS_ROLE_ARN that was hard-coded in the yml to a value that should only have been used for the development environment. But, the hardcoded value was being used in all child pipelines regardless of environment.

Steps to reproduce

  • Create a new project with the following
  • .gitlab-ci.yml
stages:
  - trigger_child

trigger_child_pipeline:
  stage: trigger_child
  variables:
    CHILD_PIPELINE_PATH: child.yml  # Path to the child pipeline definition
  trigger:
    include: $CHILD_PIPELINE_PATH
    strategy: depend
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'  # Adjust this condition as needed
  parallel:
    matrix:
      - ENVIRONMENT: [staging, production]
  • Child.yml
stages:
  - deploy

deploy_to_environment:
  stage: deploy
  variables:
    AWS_ROLE_ARN : "Local value from child.yml file"
  script:
    - echo "Deploying to $ENVIRONMENT environment."
    - echo "Deploying to $AWS_ROLE_ARN environment."
  only:
    variables:
      - $ENVIRONMENT
  • Then observe the output of the variable AWS_ROLE_ARN in the job logs

Example Project

What is the current bug behavior?

  • The variable value defined in the .gitlab-ci.yml file taking precedence

What is the expected correct behavior?

  • The project variable should take precedence

Possible fixes

Edited by 🤖 GitLab Bot 🤖