Access job variables in rules

Hello everyone

I have a problem with access to variables defined in the job, in rules:if.

In this example, the job don’t run on demo and staging.

rules-override-workflow-with-variables:
  variables:
    BRANCH_REGEX: '/staging|demo/'
  variables:
  script:
    - echo "testing rules override workflow with variables"
  rules:
    - if: '$CI_COMMIT_BRANCH =~ $BRANCH_REGEX'

I should note that I can access global variables created per pipeline.

variables:
  BRANCH_REGEX: '/staging|preprod|master|demo'

workflow:
  rules:
    - if: '$FORCE_GITLAB_CI'
    - if: '$CI_MERGE_REQUEST_IID'
      # REGEX IN VARIABLE
    - if: '$CI_COMMIT_BRANCH =~ $BRANCH_REGEX'

rules-override-workflow-with-variables:
  variables:
    BRANCH_REGEX: '/staging|demo/'
  variables:
  script:
    - echo "testing rules override workflow with variables"
  rules:
    - if: '$CI_COMMIT_BRANCH =~ $BRANCH_REGEX'

In this one, the job use the BRANCH_REGEX defined at the global scope.

Also when I try with another global variable it works. Am I missing something

variables:
  BRANCH_REGEX_LOCAL:'/staging|demo'
...
rules-override-workflow-with-variables:
  rules:
    - if: '$CI_COMMIT_BRANCH =~ $BRANCH_REGEX_LOCAL'
...

I read the docs and it doesn’t mention anything about rules not supporting job variables. Am I missing something, or rules:if does not support job variables.

Thanks

I’m currently facing a similar problem. Did you find a solution for this?