0

Using branch policies I have enabled Build validation on pull requests. Now whenever I create a pull request, I can see a build getting triggered and based on the status of the build, I am allowed to complete/hold the pull request. All fine up-to here.

Now consider a 2 parallel pull requests scenario PR1: is in progress and got a green build through Build Validation. Reviewer is allowed to complete this PR.

PR2 is also in progress, which has some changes which can fail few test cases in PR1 changes. PR2 build validation build is green and this PR2 is Approved and Completed and merged into master.

Now, PR1 is Approved (as it got a green build earlier) and completed and merged into master. Once PR1 changes are merged to master, master is now a broken branch.

How to avoid this? How can we trigger a gated check-in / pre-commit build when PR changes are actually merging in master?

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
ViBi
  • 515
  • 7
  • 19
  • Not get your latest information, is the workaround helpful for you? Or if you have any concern, feel free to share it here. – Hugh Lin Dec 25 '20 at 09:52

2 Answers2

1

There is no gated check-in / pre-commit build when PR changes are actually merging in master but you can avoid those situations easily.

In the build validation (in the branch policies) just mark in the "Build expiration" - Immediately when master is updated:

enter image description here

Immediately when branch name is updated: This option sets the build policy status in a pull request to failed when the protected branch is updated. Requeue a build to refresh the build status. This setting ensures that the changes in pull requests build successfully even as the protected branch changes. This option is best for teams that have important branches with a lower volume of changes. Teams working in busy development branches may find it disruptive to wait for a build to complete every time the protected branch is updated.

Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114
  • Thanks. This will narrow down the error window significantly but it is still not 100% error free. Also it will be an annoyance in a big development team. – ViBi Dec 17 '20 at 23:25
0

As a workaround, you can set Approvals and checks for pipleline1, and check the status of PR2 through rest api. If the status of PR2 is not completed, pipeline1 will not start running, then the Build validation of PR1 cannot be completed, and PR1 cannot be merged until PR2 is completed.

Add an Environment in the Pipeline1, and the Environment contains the check: Invoke Rest API to check the status of the Pull Request .

Environment: Pipelines -> Environemnts-> Approvals and checks -> Invoke Rest API

enter image description here

For details, here is a case you can refer to.

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25