custom variables in rules with predefined

Hi everybody! We've faced some strange behavior on gitlab 16.2.9. here is a sample .gitlab-ci.yml below.

So if we run it on master branch, we do not get NAMESPACE=latest in echo. We get NAMESPACE=master. Any other works correctly. if branch is not master - namespace is correct.

If we add a rule that checks NAMESPACE_VAR is empty - values defined in this rule will be set.

Also we noticed that if we set

  NAMESPACE_VAR:
    value: "master"    

everything works fine. But if it is set to "${CI_COMMIT_REF_SLUG}" - we have wrong values at the end.

---
variables:
  NAMESPACE_VAR:
    value: "${CI_COMMIT_REF_SLUG}"   
    description: "type a namespace for k8s cluster"  

stages:
  - deployk8s

testvar:
  stage: deployk8s
  when: manual 
  tags:
    - docker
    - linux
  rules:
    - if: '$NAMESPACE_VAR == "master"'
      variables:
        NAMESPACE: "latest"
    - if: '$NAMESPACE_VAR != "master"'
      variables:
        NAMESPACE: "${NAMESPACE_VAR}"
  script:
    - echo ${NAMESPACE_VAR} and ${CI_COMMIT_REF_SLUG} and ${NAMESPACE}
Edited by 🤖 GitLab Bot 🤖