Multiple on_stop for an environment
Release Notes
Previously, when using the environment:on_stop keyword, only one job can be specified and run as part of closing an environment. In GitLab 14.10, you can now specify multiple jobs with the on_stop keyword in your .gitlab-ci.yaml file that run in parallel when closing an environment to enable more complex environment teardown procedures.
Description
It would be beneficial if it was possible to define multiple on_stop hooks for any given environment within .gitlab-ci.yaml. According to my tests, if you have multiple jobs defining on_stop for the same environment, only the last one defined is used once the environment is being torn down (eg. the corresponding branch is deleted).
Our deployment pipelines have a deploy stage, which contains multiple jobs:
- Deploying our containers to Kubernetes using Helm, using the
devth/helmimage for running the job. - Provisioning DNS records in Cloudflare for the deployment using Terraform, using the
hashicorp/terraformimage for running the job.
Our goal was then to have each of these deploy jobs define a corresponding teardown-job so that we - in this example - would have one teardown-job running helm delete using the devth/helm image, and one running terraform destroy using the hashicorp/terraform image.
Proposal
All on_stop hooks for any given environment are collected and run in parallel or succession when the environment is being stopped.
Alternate proposal considered
on_stop could take in a list of jobs to run when the environment is being stopped, instead of just one. As far as I can tell it currently expects this being a plain string.
Implementation Details
- extend
.gitlab-ci.yamlto support multipleon-stop - implement multiple
on-stopin pipeline processing - documentation
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.