How to get build list for particular Commit through DevOps REST API

和自甴很熟 提交于 2021-02-10 20:30:41

问题


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:

  1. Load all builds for my repository through API call. Cannot find here a filter for commit:

GET https://dev.azure.com/{organization}/{project}/_apis/build/builds

  1. Then filter-out only builds with specified "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.


回答1:


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"




回答2:


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..



来源:https://stackoverflow.com/questions/58123660/how-to-get-build-list-for-particular-commit-through-devops-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!