Limiting concurrent builds for a given branch or environment
Description
Review apps and environments are great. However, consider the following situation:
-
.gitlab-ci.ymlsetup to perform a deployment to an environment corresponding to the branch - user pushes commits
- Gitlab starts to build, and deploy
- user pushes another commit, while first deployment is still going on
- Gitlab starts to build it too
At this point, we have two deployments to the same environment running concurrently, which can cause issues. Unless there's a solution I missed, the burden stays on the user to ensure that this does not happen or does not wreak havoc.
Proposal
A possibility would be to be able to forbid concurrent builds according to a key. Setting the key to $CI_BUILD_REF_NAME, or, to the environment name derived from env. variables would prevent concurrent deployments to the same environment.
This would mean that we let the 1st deployment finish, and then immediately start the 2nd deployment.
An alternative would be to be able to abort the 1st deployment when the 2nd starts. This may be more tricky, and I am not sure exactly how this would fit in.