Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps get commits linked to a work item via the REST API

Is there a way to get Git Commits that are linked to a work item given only the work item ID?

enter image description here

I'm using PowerShell and this URI to get work items, but I don't see any of the linked commits on the returned object. I also don't see any documentation on how to get these links.

$Results = Invoke-RestMethod -Uri "http://azuredevops/azuredevops/Collection/Project/_apis/wit/workitems?api-version=5.1&ids=1" -Method "GET" -UseDefaultCredentials | Select-Object -ExpandProperty Value
$Results.fields
like image 597
Zam Avatar asked Dec 10 '19 21:12

Zam


People also ask

How do you retrieve all work items associated with a release pipeline using Azure DevOps API?

Click the Repositories and the Branches Menu in the Azure DevOps Portal . Locate in the branch list the one you are going to use to build from, typically that should be your master branch, and click the options icon. Select Branch policies. Check the option ”Check for linked work items”.

How do you link work items in Azure DevOps pull request?

You can link work items to existing builds from the Add link dialog. From the Links tab of a work item, choose Add link>Existing item. From the Add link dialog, choose one of the build link types—Build, Found in build, Integrated in build— and specify the build number.

Does Azure DevOps support REST API?

Welcome to the Azure DevOps Services/Azure DevOps Server REST API Reference. Representational State Transfer (REST) APIs are service endpoints that support sets of HTTP operations (methods), which provide create, retrieve, update, or delete access to the service's resources.

Where are azure DevOps commits?

You can click on a commit ID or commit message to open the commit details page. Build and PR information - You can view the pull request that brought this commit to the branch selected on the page, and view the build status of the current commit.


1 Answers

You are very close to the correct solution.

The commits which linked to the work item is relation of work item. So, here, you need to specify $expand in API to get the corresponding commits content.

Get https://dev.azure.com/{org name}/{project name}/_apis/wit/workitems/{id}?$expand=relations&api-version=5.1

Then you would see the commits in relations part of the response body:

enter image description here

like image 105
Mengdi Liang Avatar answered Sep 18 '22 00:09

Mengdi Liang