[英]Azure Devops Rest API- Get builds currently queued in Agent Pool
有沒有辦法只從 Azure DevOps 休息 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
如果您不想迭代所有構建(有意義),您可以通過以下方式檢索等待構建:
$waitingBuilds = $json.value | where {-not $_.assignTime}
# Then print the details
我需要同樣的東西,但我在 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')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.