Cancel potentially redundant pipelines automatically
Description including problem, use cases, benefits, and/or goals
When pipeline runs are queueing, it's often a waste to run tests on every incremental change on the same branch. On
gitlab-ce repo we push often and end-up in long build queues. Let's introduce a feature that would say, run build only if the commit is the HEAD of the branch.
There's lots of ways to do this. Some options:
When adding a pipeline to the queue, check if there are other pipelines already queued for the same ref, and if so, delete the old ones (or don't queue the new one) such that only one run will be queued at a time.
When adding a pipeline to the queue, not only delete other queued entries for the same ref, but kill any running pipelines too. This is more aggressive, but runs the systemic risk of never finishing a pipeline.
When pulling builds off of the queue, abort any for a SHA that is non-HEAD. This leaves builds in the queue and puts the cleanup at pull-time rather than push-time.
We have awesome when.
We can extend it with:
It will make the pending build be run only if the commit is the HEAD of the branch. If it's not the build will be marked as
skipped that would require to introduce additional status).
job: script: echo test when: if_latest only: - branches
We do it simple. Whenever we receive a push, creating a pipeline, we also check if there are other pipelines which are from the same branch, created of pending, non-HEAD, and cancel all of them.
This is controlled by a new setting: "Auto-cancel redundant, pending pipelines" as a project setting. Pipelines cancelled this way would have a tooltip showing that it's auto-cancelled.