How to auto stop an environment for cross-project pipelines
I am having an issue with environments for a pipeline that is triggered from a different project. I use a bridge job in the upstream project like so in the snippet below:
start_mr_job:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "development"'
stage: deploy
script:
- echo "do something once bridge job done.."
needs:
- job: bridge_job
bridge_job:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "development"'
variables:
UPSTREAM_BRANCH: $CI_COMMIT_REF_SLUG #branch name
stage: terraform
trigger:
project: group_xyz/downstream-project
branch: development
strategy: depend
As you can see, it is an MR pipeline. I need the strategy: depend
to be sure some variables are set from downstream. Downstream, I have a terraform pipeline that has two last stages like so in the snippet below:
Apply:
stage: Terraform_Env
allow_failure: false
only:
- pipelines
script:
- echo "provision resources..set some variables"
dependencies:
- Plan
artifacts:
when: on_success
expire_in: 1 hour
name: outputs
reports:
dotenv: deploy.env
environment:
name: review/$UPSTREAM_BRANCH
on_stop: Destroy
auto_stop_in: 1 hour
Destroy:
stage: Terraform_Env
only:
- pipelines
when: manual
environment:
name: review/$UPSTREAM_BRANCH
action: stop
script:
- echo "take down resources.."
The review/$UPSTREAM_BRANCH
environment is created as expected but the environment is not auto stopped as expected. Left it overnight to be sureā¦
On the other hand, the manual stop does work as expected
This terraform.gitlab-ci.yml template and has been a key reference plus environments documentation.
Is there something I am doing wrong? My projects are on Gitlab.com, free tier.
Appreciate all help, thanks!