问题
We recently made a change to our build validation gate on PRs such that the builds expire "immediately" if another commit makes it into master branch before the current PR completes. See here.
Even though this change ensures that the master is always accurate/buildable/healthy, this seems to have few negative effects on developer productivity :
- team members have to continuously keep an eye on their PRs to requeue builds validations.
- Not only they have to requeue builds manually, but prior to doing that they have to manually rebase their branch before requeueing.
- as we move towards more smaller/shippable checkins in to master, the no. of times this occurring is expected to increase.
I want to automate (1) and (2). Is there a way I can setup VSTS build validation such that for all open PRs, upon build expiry, it automatically rebases/remerges the source branch with master and then requeues the build ?
回答1:
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 breakmaster
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 fixmaster
.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.
来源:https://stackoverflow.com/questions/49455911/vsts-automatically-rebase-merge-and-requeue-build-validation-gate-in-case-of-b