How do I integrate branch deploys with GitLab review apps?

Thanks to the Continuous Deployment settings in Netlify, deploying Merge Requests are quite easy.

But we found that when builds are not triggered form GitLab CI, it is very hard to link those deploy previews into the MR environment URL.

I know Netlify has webhook notifications, but it seems that GitLab has no known way to attach URL to the environment/MR other than gitlab-ci.yml, but then Netlify branch deploys has no documented way to manually specify sub-domains, even with the “–” namespace.

Is there a workaround for this situation?

1 Like

Answering my own question, and for others in the future.

Last year Netlify decided to ditch the whole developer experience created by GitLab and go with a random comment in the GitLab MR to track it.

  1. Source discussion in GitLab
  2. The Netlify’s way to add that comment with your own name.

thanks for showing us what you came up with! That’s definitely helpful to others!

Or can add dummy steps to pipeline to set it:

review_app:
  stage: deploy
  only:
    - merge_requests
  before_script: []
  script:
    - echo "Deploy Review Ready"
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://deploy-preview-$CI_MERGE_REQUEST_IID--project.netlify.app/#/
    on_stop: stop_review_app
  dependencies: []

stop_review_app:
  stage: deploy
  only:
    - merge_requests
  variables:
    GIT_STRATEGY: none
  script:
    - echo "Stopped"
  when: manual
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  dependencies: []

Also Gitlab Issue tracking this : Support Netlify Deploy Previews as Review Apps (#27312) · Issues · GitLab.org / GitLab · GitLab