未通过 Azure DevOps API 获取完整的管道运行信息

时间:2021-02-09 21:10:37

标签: azure-devops azure-devops-rest-api

为了解决这个问题 Creating a dashboard for the last branch deployed through pipelines,我想我会尝试使用 Azure DevOps API。它在大多数情况下运行良好,但是我观察到 GET Run API 没有返回多仓库管道 (https://docs.microsoft.com/en-us/rest/api/azure/devops/pipelines/runs/get?view=azure-devops-rest-6.0) 的所有存储库信息。它似乎只返回 self 存储库的数据。例如,我的一次运行的响应负载如下所示:

    "resources": {
        "repositories": {
            "self": {
                "repository": null,
                "refName": "refs/heads/master",
                "version": "commit-hash"
            }
        }
    },

尽管在管道中检查了其他几个存储库。这是错误还是预期?有解决方法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

我们可以通过 F12 获取 REST API,这个 REST API 是 https://dev.azure.com/{Org name}/{Project name}/_build/results?buildId={Build ID}&__rt=fps&__ver=2

Power shell 脚本:

cls

$connectionToken="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$URL = "https://dev.azure.com/{Org name}/{Project name}/_build/results?buildId={Build ID}&__rt=fps&__ver=2"
$Result = Invoke-RestMethod -Uri $URL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get 
Write-Host "This build sources are"$Result.fps.dataProviders.data."ms.vss-build-web.run-details-data-provider".repositoryResources.alias

结果:

enter image description here

注意:此 yaml 文件保存在存储库 sample 中,self 存储库是 sample 存储库