简体   繁体   中英

TFS 2017 Update 2 - Use REST API to trigger Pull Request Validation Build

The TFS 2017 Update 2 added the feature for manually starting pull request builds.

Manual triggers are useful for things like automated test runs that might take a long time to run, and you only really need to run once before completing the pull request

TFS Update Releasenotes

As seen in Builds REST API Reference I would now want to trigger a validateShelfset Build, as pressing the button

队列构建以进行拉取请求验证

would do. When I compared my JSON Request builds with the "Button pressed" builds via http://MYTFS:8080/tfs/COLLECTION/PROJECT/_apis/build/builds?api-version=3.0 the only notable difference was

reason: "validateShelveset",

and the parameterlist. So I changed my JSON to:

POST http://MYTFS:8080/tfs/COLLECTION/PROJECT/_apis/build/builds?api-version=3.0

Calling POST content:

{
  "definition": {
    "id": 2
  },
  "sourceBranch": "refs/pull/26/merge",
  "reason": "validateShelveset",
  "parameters": "{\"system.pullRequest.pullRequestId\":\"26\",\"system.pullRequest.sourceBranch\":\"refs/heads/feature/myfeaturebranch\",\"system.pullRequest.targetBranch\":\"refs/heads/develop\"}"
}

But while web-UI started builds are seen as Pull Request builds, and have the reason validateShelveset

拉取请求构建

the POST started builds are seen as private.

在此处输入图片说明

I even tried (just to see whether using the reason field would be recognized by TFS) the reason: checkInShelveset, which TFS Recognized correctly as such a build.

Basically all I want to do is to emulate the "Queue build" button in a cmdline interface, and when I look at the Build API it seems as if I am doing the right thing; am I missing something obvious? The documentation does not cover how to add the (quite newly added feature) manual Pull request builds.

Based on my test, you can use the REST API with PATCH method to trigger the Pull Request Validation Build.

  1. Use the API tracking tools such as Fiddler to track API.
  2. Trigger the Pull Request Validation Build with PATCH method use the tracked REST API (invoke the REST API directly, no need to provide the JSON content.):

eg:

PATCH http://server:8080/tfs/DefaultCollection/feb1793b-4d91-4be4-8373-02216ec5c36b/_apis/policy/Evaluations/0891d5a4-fee9-4751-8bc6-ff403c2860f1?api-version=3.2-preview 

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM