Reputation: 5486
I need to retrieve a list of builds associated with particular Commit (see a picture of TFS UI) through Azure DevOps REST API. I can do it by using brute force:
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds
"commitId": "eed1b008520c2b32669bef9a0a08be8a50b6e8a4"
But this is extremely inefficient solution. Can you help me if there is a more efficient way? I tried to load details for Commit with links, but there is no link to build or builds.
Upvotes: 4
Views: 2677
Reputation: 5486
There is Statuses API for Commit. It seems that when starting and ending build, the appropriate status is posted.
So when I call
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}/statuses?api-version=5.1
I get all last builds associated with the Commit and their statuses.
Thanks to Hugh Lin for showing me direction..
Upvotes: 4
Reputation: 19481
There should be no other ways to get builds for particular commit through the rest api except for retrieval via commitId. We can't filter the returned result with the commitId or sourceVersion as parameters.
If you feel that getting all the builds and then filtering through the commitId is extremely inefficient, the easiest way to do it in UI: In Commits, you query the specified commit through commitId. In the pipeline status tab of this commit, all relevant builds are displayed. As shown in your figure, you can click on a specific build to jump to the detailed page of the build.
Another challenging way is to press F12
in the browser then select Network
to capture the request. You can capture the buildId in the response body, and then you can get the builds with rest api based on the buildId.
You need to write script to parse the buildId from "targetUrl":"vstfs:///Build/Build/xxx"
Upvotes: 1