Dynamic generated URL for environment

Hi everyone,

I’m currently using Gitlab to deploy my website on Netlify.
I designed a workflow where every merge requests are deployed using a review-app through Netlify while the master branch is deployed on the production URL.

When a merge request is successfully deployed on Netlify using netlify-cli, the CLI outputs (stdout) a unique generated URL where the website is deployed on.

I’m struggling to extract this URL and to create a dynamic environment at runtime.
Indeed I would like to have a “button” displayed on the PR to have quick access to the version deployed.
Does someone know if such things are possible with gitlab-ci ?

Thanks for your help


if you have access to the variable value inside your CI job’s shell, you could for example use the REST API and modify the merge request comment (or add a new one to start with). This comment needs to include a Markdown formatted URL then. If you are more into buttons, font-awesome icons with HTML might also be possible, at least as long as GitLab itself uses these sets.

Do this step by step, and post your results here please.


FWIW, here’s a way I got it working with a Gatsby site:

    - apt-get update && apt-get install -y jq curl
    - npm i
    - npm run build
    - npm i -g netlify-cli
    - NETLIFY_JSON=$(netlify deploy --site $NETLIFY_SITE_ID --auth $NETLIFY_AUTH_TOKEN --json)
    - DEPLOY_URL=$(echo $NETLIFY_JSON | jq -r ".deploy_url")
    - MR_DESCRIPTION=$(curl "https://my-gitlab-instance/api/v4/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID?private_token=$PRIVATE_ACCESS_TOKEN" | jq -r ".description")
    - 'curl -X PUT -H "Content-Type: application/json" -d "{\"description\":\"$MR_DESCRIPTION\"}" "https://my-gitlab-instance/api/v4/projects/$CI_PROJECT_ID/merge_requests/$CI_MERGE_REQUEST_IID?private_token=$PRIVATE_ACCESS_TOKEN"'    

note that you need to create a gitlab personal access token for this

1 Like