Gitlab environment URL not set when variables come from rules section

Hey, did anybody encounter an issue when Gitlab doesn’t pick the environment URL from a job if the URL comes from variables defined in the rules section?

Here is my job configuration. The environment name is correctly set, but the URL is empty in Gitlab. Therefore there is no button “View the latest deployment”.

deploy:
    interruptible: false
    stage: deploy
    variables:
        ENVIRONMENT_NAME: "review/$CI_COMMIT_REF_SLUG"
    rules:
        -   if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
            when: on_success
            variables:
                ENVIRONMENT_NAME: "staging"
                BASE_DOMAIN: example.com
                DOMAIN: api.$BASE_DOMAIN
        -   when: on_success
            variables:
                BASE_DOMAIN: example.com
                DOMAIN: $CI_ENVIRONMENT_SLUG-api.$BASE_DOMAIN
    environment:
        name: $ENVIRONMENT_NAME
        url: https://$DOMAIN
        on_stop: "stop:environment"
    script:
        ...

I’m trying to figure out what I’m doing wrong. :confused: