Cancel preview build for a branch when a new build is started

Restarting the previous discussion because I missed the chance to reply before it closed: Cancel preview build for a branch when a new build is started

From previous post:

Our team uses Vercel Preview in our CI pipeline as a smoke test before merging code into main to make sure that the code builds successfully. The current issue for our team is that devs frequently publish a new PR, realize they need to make additional changes, and then push new changes into the PR shortly after. This triggers 2 preview build processes for the same PR

However, with the way we use our preview as a smoke test, we only need the latest build to succeed since any previous builds don’t reflect the current state of the PR. We do realize that devs can manually cancel previous builds, but this doesn’t easily scale with team size as it requires consistent human behavior/habits/reinforcement

Does Vercel offer any simple way to automatically cancel previous builds for a branch when a new build is triggered on that same branch?

The current reply was that “Vercel automatically cancels previous builds when a new commit is pushed to the same Pull Request branch.” However, this doesn’t seem to be our experienced behavior. I’ve attached a screenshot from a video I took of this behavior. It seems all new commits on a feature branch wait for the previous commit to finish building before starting.

Hey @jamisonsavvywealth. The auto job cancelation feature will still complete the in-progress build, but will then skip ahead to the most recent commit.

With each new push, if Vercel is already building a previous commit on the same branch, the current build will complete and any commit pushed during this time will be queued. Once the first build completes, the most recent commit will begin deployment and the other queued builds will be cancelled.

Please let me know if you have any other questions :slightly_smiling_face:

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.