Azure DevOps Rest API- 获取当前在代理池中排队的构建任务

6
有没有办法从Azure DevOps rest API中仅获取等待特定池可用代理的构建?目前我有这个端点,它为我提供了在池中发生的所有作业请求:https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolid}/jobrequests。我查看了API文档,但没有找到任何关于代理池的信息。
2个回答

3

我也需要这个东西,但我使用的是Linux。在Linux上等价于@shayki-abramczyk的答案是:

jobRequests=$(curl -u peterjgrainger:${{ YOUR_DEVOPS_TOKEN }} https://dev.azure.com/{your_org}/_apis/distributedtask/pools/{your_pool}/jobrequests?api-version=6.0)
queuedJobs=$(echo $jobRequests | jq '.value | map(select(has("assignTime") | not)) | length')
runningJobs=$(echo $jobRequests | jq '.value | map(select(.result == null)) | length')

PowerShell也可在Linux上使用! - MEMark
谢谢您不仅提供了筛选步骤,还提供了端点! - scrthq

1
没有现成的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

如果您不想迭代所有有意义的构建,您可以通过以下方式检索等待的构建:
$waitingBuilds = $json.value | where {-not $_.assignTime} 
# Then print the details

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接