Why triggering a job using custom defined variable not working as described

According to this example from gitlab docs

job1:
  variables:
    VAR1: "variable1"
  script:
    - echo "Test variable comparison
  rules:
    - if: $VAR1 == "variable1"

I should be able to use custom defined variable to control job execution, however, the only way I got this working is if I were to hard code the value of the variable in variables which isn’t very useful.

What I was aiming for was to be able to dynamically add value to VAR1 like this VAR1:${NEW_VARIABLE_VALUE}

here is my example below, the only why I got this working is by hard coding the value of VAR1 in the job itself which doesn’t make sense.

job1:
  stage: build
  script:
    -  export VAR_EXAMPLE="test"

job2:
  stage: maybe
  variables:
    VAR1: "${VAR_EXAMPLE}"
  trigger:
     include: .my-child.yml
  rules:
    - if: $VAR1 == "test"

I checked and verified that the value of $VAR_EXAMPLE defined in job1 is available to the entire pipeline but I don’t understand why then it is ignored in the rules of job2.

If anyone has any insights on what’s going on here please share.
Thank you.