如何通过 Azure 中的 REST API 获取链接到构建管道的工作项列表

How to get the list of work items linked to a build pipeline via the REST API in Azure

我想使用 Azure Rest API 从某些 PowerShell 脚本中获取链接到当前构建管道的工作项列表 (id),我该怎么做?

Azure DevOps 服务器 2019

How to get the list of work items linked to a build pipeline via the REST API in Azure

有一个现成的 API 来获取链接到构建管道的工作项列表:

Builds - Get Build Work Items Refs::

GET https://{instance}/{collection}/{project}/_apis/build/builds/{buildId}/workitems?api-version=5.0

powershell 脚本:

$url = "http://{instance}/{collection}/{project}/_apis/build/builds/2945/workitems?api-version=5.0"
$LinkedworkItems= Invoke-RestMethod -Uri $url -Headers @{   
 Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
} -Method Get

Write-Host "Linked work items= $($LinkedworkItems| ConvertTo-Json -Depth 100)"

注意:需要进入代理阶段并select允许脚本访问 OAuth 令牌:

结果:

希望对您有所帮助。