Azure Devops Rest API-获取当前在代理程序池中排队的生成 [英] Azure Devops Rest API- Get builds currently queued in Agent Pool

查看:96
本文介绍了Azure Devops Rest API-获取当前在代理程序池中排队的生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以从Azure DevOps rest API中仅获取正在队列中等待特定池中的可用代理的生成?

Is there a way to only get the builds that are waiting in queue for an available agent in a specific pool from the Azure DevOps rest API?

我目前有一个端点,可以为我提供池中发生的所有作业请求:

I currently have this endpoint that provides me with all the job requests that occurred in the pool:

https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolid}/jobrequests

我浏览了API文档,但找不到与代理程序池有关的任何内容.

I looked through the API documentation and am unable to find anything regarding agent pools.

推荐答案

虽然没有现成的API,但是我们可以使用常规API并过滤结果.

There is no out of the box such API, but we can use the regular API and filter the results.

例如,我使用您提供的API,并在池中获得了所有构建,然后,我使用PowerShell过滤了结果,以仅获得等待可用代理的构建.

For example, I use the API you provided and I got all the builds in the pool, then, I filtered the results with PowerShell to get only the builds that waiting for an available agent.

我怎么知道谁在等待?在JSON结果中,每个构建都有一些属性,如果该构建开始在代理上运行,他将获得一个属性assignTime,因此我将搜索没有此属性的构建.

How do I know who waiting? in the JSON result, to each build have some properties, if the build started to run on an agent he got a property assignTime, so I search builds without this property.

#... 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

如果您不想迭代所有有意义的构建,则可以通过以下方式检索等待的构建:

If you don't want to iterate on all the builds (that make sense) you can retrieve the waiting builds in this way:

$waitingBuilds = $json.value | where {-not $_.assignTime} 
# Then print the details

这篇关于Azure Devops Rest API-获取当前在代理程序池中排队的生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆