powershell - 使用 Build Agent Name 获取 Build Agent ID
问题描述
在触发回归之前,我正在使用 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 :
任何指导将不胜感激。
解决方案
由于它在值中返回一个数组,因此不显示。我将它用作:$poolresponse.value[$i]在 for 循环中它工作得非常好。
虽然感谢@LotPings 的帮助。
推荐阅读
- java - 如何将同一活动的开启次数限制为 5 次?
- docker - 来自 docker 容器的 ssh
- css - CSS:如何在跨度或 div 中垂直对齐文本
- javascript - 将基于类的组件转换为基于函数的组件
- python - Django ValidationError: [""('1',)" value 必须是 True、False 或 None。"]
- python - 具有元组键的字典的平均值
- mongodb - mongodb - 将 $addField 与 $exists 结合起来
- node.js - AWS节点js lambda使用gm imagemagick调整大小,裁剪和单色超时
- istio - 在 istio 中,主体名称是如何创建的?
- c++ - 单例类构造函数的问题在此上下文中是私有的