Search code examples
tfsazure-devops-server-2019

Pull request policies - Build expires after another pull request was completed. Way to automatically rerun expired builds for other PRs?


This is somewhat similar to Pull request policies - Build expired - How can I run the build again? but looks at the automation side.

Our context: We have pull requests which protect our master branch and each completed pull requests expires the builds of all other pull requests to ensure that the builds of all of the remaining pull requests have to be re-queued and build and test correctly.

Now we have times where we get pull request contention (I am looking at you, end-of-sprint!) in these times we have plenty of pull requests open. While we are working on minimizing the amount, it sometimes just happens.

Is there a plugin or some feature I am missing that actually can trigger all of those expired builds after a PR completes automatically? There is a way to automatically expire all other PR builds, so I would have thought that there is also a way to re-queue them automatically. I know this might trigger a build cascade but I would like to have my PRs always as up-to-date as possible.


Solution

  • Related REST API is not documented, however you can track it by tools such as Fiddler or press F12 in Chrome browser then select Network.

    In the pull request page to manually queue the build as mentioned in your question.

    enter image description here

    For example with my azure devops service, I get below API

    Post https://dev.azure.com/patricklu/_apis/Contribution/dataProviders/query/project/a72e1ef5-4921-49c5-9260-e72b7bff977d
    

    Request Body:

    {"contributionIds":["ms.vss-code-web.pull-request-detail-policy-data-provider"],"context":{"properties":{"repositoryId":"357893bf-9a1f-4ee4-95d3-c5ceda4f4abc","pullRequestId":12,"policyEvaluationIds":["bca44f9f-268f-4640-aa7e-af5253b3b11e"],"pageSource":{"contributionPaths":["VSS","VSS/Resources","q","knockout","mousetrap","mustache","react","react-dom","react-transition-group","jQueryUI","jquery","OfficeFabric","tslib","@uifabric","VSSUI","ContentRendering","ContentRendering/Resources","TFSUI","TFSUI/Resources","WidgetComponents","WidgetComponents/Resources","Charts","Charts/Resources","TFS","Notifications","Presentation/Scripts/marked","Presentation/Scripts/URI","Presentation/Scripts/punycode","Presentation/Scripts/IPv6","Presentation/Scripts/SecondLevelDomains","highcharts","highcharts/highcharts-more","highcharts/modules/accessibility","highcharts/modules/heatmap","highcharts/modules/funnel","Analytics"],"diagnostics":{"sessionId":"8277adc6-6810-4cf9-b984-10860e90c0b5","activityId":"8277adc6-6810-4cf9-b984-10860e90c0b5","bundlingEnabled":true,"cdnAvailable":true,"cdnEnabled":true,"webPlatformVersion":"M156","serviceVersion":"Dev17.M156.1 (build: AzureDevOps_M156_20190821.17)"},"navigation":{"topMostLevel":8,"area":"","currentController":"Apps","currentAction":"ContributedHub","currentParameters":"12","commandName":"Git.pullrequest","routeId":"ms.vss-code-web.pull-request-review-route","routeTemplates":["{project}/{team}/_git/{GitRepositoryName}/pullrequest/{parameters}","{project}/_git/{GitRepositoryName}/pullrequest/{parameters}","_git/{project}/pullrequest/{parameters}"],"routeValues":{"project":"GITAgile","parameters":"12","controller":"Apps","action":"ContributedHub","vctype":"git","viewname":"pull-request-review"}},"project":{"id":"a72e1ef5-4921-49c5-9260-e72b7bff977d","name":"GITAgile"},"selectedHubGroupId":"ms.vss-code-web.code-hub-group","selectedHubId":"ms.vss-code-web.pull-request-hub","url":"https://dev.azure.com/patricklu/_git/GITAgile/pullrequest/12?_a=overview"},"sourcePage":{"url":"https://dev.azure.com/patricklu/_git/GITAgile/pullrequest/12?_a=overview","routeId":"ms.vss-code-web.pull-request-review-route","routeValues":{"project":"GITAgile","parameters":"12","controller":"Apps","action":"ContributedHub","vctype":"git","viewname":"pull-request-review"}}}}}
    

    enter image description here

    As you can see there is some value such as repository ID and pull Request ID. Follow this, you should be able to user API to rerun some builds for a specific Pull Request.

    You could use Azure DevOps Services service hooks or Rest API to track pull request completed or not, then use above API call to re-run the build. Hope this helps.