I've run into this exact problem at my organization. Setting Build expiration to Immediately becomes too burdensome when there are multiple PRs all trying to get into the same time.
AFAIK - there's no way to automatically trigger a rebuild of all PRs targeting master
whenever master
is updated. I'm sure the basics are there if you want to hook into VSTS events and write the code yourself. But there's nothing out-of-box last time I looked.
What my organization did was to accept a compromise. We configure PRs so the build expires after 1 hour. This way there's no contention when multiple PRs are trying to be merged at the same time. However, this has the downside you describe in your original question VSTS : Invalidating builds on existing PRs when another commit makes it into master branch where it's possible for the target branch (ie master
) to become broken because of a quick merger of two incompatible PRs.
We've ended up just embracing this limitation
We have a trigger on all of our branches (feature, master
, etc) that whenever new commits are added, we automatically trigger a new build. This way if a PR managed to break master
we get an email about it within a few minutes.
If the main branch (ie master
) becomes broken, all new PRs will start failing builds. Thus, no new PRs can be merged in. This usually gets everyone's attention so the problem quickly bubbles up to the surface - and the whole team starts working to fix master
.
Before we deploy master
we run a full VSTS build, including unit tests. This way, if the main branch is broken (by two incompatible PRs or for any other reason) we make sure we halt the deployment.
So, unfortunately, we can't guarantee that master
is always a 100% in a good state. Getting to 100% is just has too much negative impact on our workflow and productivity. So we embrace our limitations and make sure we are notified asap and can handle the situation when the branch breaks.