Passing Gitlab variable from one stage to another stage rules

I am trying to pass variable values from one stage to another stage and using it with “rules”. code snippet is given below.

build-job:
  stage: build
  script:
    - echo "Build start"
    - VAR1=yes >> variables.env
    - echo $VAR1
  artifacts:
    reports:
      dotenv: variables.env
trigger-pipeline:
  stage: child
#  when: manual
  trigger:
    include: child/.gitlab-ci.yaml
  needs:
    - job: build-job
      artifacts: true
  rules: 
    - if: $VAR1 == "yes"

Expected output: child pipeline will be triggered.

Hello,

Can somebody help me here? thanks