Skip to content

Add new MR environment auto-stop logic

What does this MR do and why?

This MR creates a new association between Environments and Merge Requests so we can keep track of which environments were created by an MR. The logic in Environments::StopService is updated to only stop environments associated with an MR if any are found. If not, the old logic is run to accommodate existing MRs. We should be able to remove the old logic after some time (see #372965).

Related to #299412 (closed)

Screenshots or screen recordings

In the screen recordings below, a development environment exists before opening an MR. The MR deploys to both development and a review/$CI_COMMIT_REF_NAME environment. The MR is then closed.

Before

Both the development and review/$CI_COMMIT_REF_NAME environments are stopped when the MR is closed.

before

After

Only the review/$CI_COMMIT_REF_NAME environment is stopped when the MR is closed.

after

How to set up and validate locally

.gitlab-ci.yml:

stages:
  - deploy

deploy-dev:
  stage: deploy
  script:
    - echo "Deploying..."
  environment:
    name: development
    on_stop: stop-dev
  only:
    - merge_requests

stop-dev:
  stage: deploy
  script:
    - echo "Stopping..."
  environment:
    name: development
    action: stop
  when: manual
  only:
    - merge_requests

deploy-review:
  stage: deploy
  script:
    - echo "Deploying..."
  environment:
    name: review/$CI_COMMIT_REF_NAME
    on_stop: stop-review
  only:
    - merge_requests

stop-review:
  stage: deploy
  script:
    - echo "Stopping..."
  environment:
    name: review/$CI_COMMIT_REF_NAME
    action: stop
  when: manual
  only:
    - merge_requests

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Alishan Ladhani

Merge request reports

Loading