BlogCI/CD
GitLab review apps: a fresh environment per merge request
Spin up an ephemeral deploy for every merge request and tear it down on merge — review real changes, not screenshots.
A review app is a full, running deploy of a branch, created when a merge request opens and destroyed when it merges or closes. Reviewers click a link and use the actual change instead of imagining it from a diff. GitLab builds this from two pipeline jobs and a dynamic environment.
Deploy on merge request
.gitlab-ci.yml
review:stage: deployscript:- helm upgrade --install mr-$CI_MERGE_REQUEST_IID ./chart \--set host=$CI_COMMIT_REF_SLUG.review.acme.devenvironment:name: review/$CI_COMMIT_REF_SLUGurl: https://$CI_COMMIT_REF_SLUG.review.acme.devon_stop: stop_reviewrules:- if: $CI_MERGE_REQUEST_IID
Tear it down automatically
.gitlab-ci.yml
stop_review:stage: deployscript:- helm uninstall mr-$CI_MERGE_REQUEST_IIDenvironment:name: review/$CI_COMMIT_REF_SLUGaction: stoprules:- if: $CI_MERGE_REQUEST_IIDwhen: manual
1
MR opens
review job runs
2
Env created
link on the MR
3
Reviewers
use the real app
4
MR merges
stop_review cleans up
Cap the sprawl
Give review namespaces a resource quota and a TTL sweeper. Abandoned MRs otherwise leave environments running and billing.