Kev*_*vin 6 azure azure-devops azure-devops-rest-api
有没有办法只从 Azure DevOps Rest API 获取在特定池中等待可用代理的构建?
我目前有这个端点,它为我提供池中发生的所有作业请求:
https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolid}/jobrequests
我查看了 API 文档,但找不到有关代理池的任何内容。
没有开箱即用的此类 API,但我们可以使用常规 API 并过滤结果。
例如,我使用您提供的 API 并获取池中的所有构建,然后使用 PowerShell 过滤结果以仅获取等待可用代理的构建。
我怎么知道谁在等?在 JSON 结果中,每个构建都有一些属性,如果构建开始在代理上运行,他就会获得一个属性assignTime
,所以我搜索没有此属性的构建。
#... Do the API call and get the repsone
$json = $repsone | ConvertFrom-Json
$json.value.ForEach
({
if(!$_.assignTime)
{
Write-Host "Build waiting for an agent:"
Write-Host Build Definition Name: $_.definition.name
Write-Host Build Id: $_.owner.id
Write-Host Queue Time $_.queueTime
# You can print more details about the build
}
})
# Printed on screen:
Build waiting for an agent:
Build Definition Name: GitSample-CI
Build Id: 59
Queue Time 2019-01-16T07:36:52.8666667Z
Run Code Online (Sandbox Code Playgroud)
如果您不想迭代所有构建(有意义),您可以通过以下方式检索等待的构建:
$waitingBuilds = $json.value | where {-not $_.assignTime}
# Then print the details
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2418 次 |
最近记录: |