I currently have a pipeline running which deploys review apps to an environment. I am using the “Merged results pipelines” feature and so a pipeline is only run once a merge request has been opened for a particular branch. I also have the merge trains feature enabled as well if that makes any difference.
The problem I am having, is that the “stop environment” job is not being automatically triggered once the merge request has been merged into main branch.
Here is the related section of my gitlab-ci.yml
file:
.Deploy Review:
stage: Deploy
image:
name: ...
entrypoint: [""]
dependencies: []
script:
- echo "Hi"
Deploy Review:
extends: .Deploy Review
environment:
name: $CI_COMMIT_REF_SLUG-$CI_MERGE_REQUEST_IID-review/app
url: <url>
deployment_tier: development
on_stop: Teardown Review
rules: !reference [.merge-request-with-app-changes, rules]
.Teardown Review:
stage: Deploy
image:
name: ...
entrypoint: [""]
variables:
GIT_STRATEGY: none
script:
- echo "Teardown..."
when: manual
Teardown Review:
extends: .Teardown Review
dependencies:
- Deploy Review
needs: ["Deploy Review"]
environment:
name: $CI_COMMIT_REF_SLUG-$CI_MERGE_REQUEST_IID-review/app
action: stop
rules: !reference [.merge-request-with-app-changes, rules]
And then my reference rules are in another file like so:
.app-only-code-changes:
rules:
- changes: &only_app_code_changes_array
- app/**/*
.merge-request-with-app-changes:
rules:
- if: '$CI_MERGE_REQUEST_EVENT_TYPE == "merged_result"'
changes: *only_app_code_changes_array
I’m also wondering which pipeline should actually be responsible for running the “stop environment” job? Should it be triggered from the last merge results pipeline for that merge request?
Any advice is much appreciated.