【发布时间】:2020-01-06 17:45:38
【问题描述】:
在触发回归之前,我正在使用 Powershell 脚本自动化构建代理的过程,该脚本将在每天的设定时间运行。我无法使用构建代理名称获取构建代理 ID,其中构建代理名称将由用户提供并可在排队时设置。
尝试搜索这方面的所有内容,但还没有发现任何有用的东西(在我的上下文中)。我围绕这部分尝试了一些代码。主要关心的是我能够得到计数,但现在是值。检查输出,我得到以下是我尝试过的代码。
// Getting the list of Agent ID's from the Environmental Variables, splitting & saving in an array.
$agentID = $env:agentIDs -split ","
$URI = "https://URL.com/_apis/distributedtask/pools/xx/agents"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type","application/json")
$headers.Add("Authorization","Bearer $env:SYSTEM_ACCESSTOKEN")
foreach ($element in $agentID)
{
$poolresponse = Invoke-RestMethod -Uri $URI -Method GET -Headers $Headers
echo $poolresponse
// Count is giving the count correct.
echo "count : $($poolresponse.count)"
// However struggling with getting the value.
echo "value : $($poolresponse.value)"
}
实际输出:
count value
----- -----
10 {@{systemCapabilities=; _links=; maxParallelism=1; createdOn=; authorization=; id=133;...}]}
count : 10
value :
我们将不胜感激。
【问题讨论】:
-
当您使用 foreach 迭代
$agentID时 - 在 Invoke-RestMethod 中没有 使用 $element 它每次都会返回相同的响应.要扩展value,请使用. property dereference operator=>$poolresponse.value
标签: powershell devops