我想用TFS 2015 REST API来解决代理是否忙碌的问题。 我试图从代理商那里得到请求,但似乎只列出了已完成的请求:
http://tfsserver:8080/tfs/_apis/distributedtask/pools/2/jobrequests?agentId=41
我查了所有可能的api电话,但我无法弄明白,如果和座席有没有运行构建,我怎么能得到。
是的,有人可以帮助我。谢谢!
答案 0 :(得分:1)
如果值中包含项"result"
(例如:"result": "succeeded"
),则只需检查响应的最新请求(排名第一的请求),然后检查代理闲着,否则它很忙。
简而言之:
空闲:
"result": "succeeded",
或"result": "abandoned",
或"result": "succeededWithIssues",
忙:
否“结果”项目
您可以使用以下PowerShell脚本来识别,如果结果为空,则代理忙:
$serverurl = "http://tfsserver:8080/tfs"
$poolid = "39"
$agentid = "147"
$baseUrl = "$serverurl/_apis/distributedtask/pools/$poolid/jobrequests?agentId=$agentid"
$response = (Invoke-RestMethod -Uri $baseUrl -Method Get -UseDefaultCredential).value
$requests = @()
foreach($request in $response){
$customObject = new-object PSObject -property @{
"RequestId" = $request.requestId
"Result" = $request.result
"AgentName" = $request.reservedAgent.name
"AgentVersion" = $request.reservedAgent.version
"AgentStatus" = $request.reservedAgent.status
"BuildDefinitionID" = $request.definition.id
"BuildDefinitionName" = $request.definition.name
"BuildID" = $request.owner.id
"BuildName" = $request.owner.name
}
$requests += $customObject
}
$requests | Select-Object -first 1 `
RequestId,
Result,
AgentName,
AgentVersion,
AgentStatus,
BuildDefinitionID,
BuildDefinitionName,
BuildID,
BuildName
实际上,最简单的方法是通过门户网站检查agnet状态:
管理项目(齿轮图标) - > 代理商池 - >选择特定的代理池和代理 - >检查请求