如何从 PowerShell 以编程方式列出 VSTS 代理池? [英] How to list VSTS agent pools programmatically from PowerShell?

查看:15
本文介绍了如何从 PowerShell 以编程方式列出 VSTS 代理池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想连接到 VSTS 并获取代理池列表.我想枚举代理池,然后删除 VSTS 服务器上的代理.我在 VSTS API 参考中找不到有关如何执行此操作的任何文档.

I want to connect to VSTS and get a list of agent pools. I want to enumerate the agent pools and then delete agents on the VSTS server. I can't find any documentation for how to do this in the VSTS API reference.

我正在像这样连接到 VSTS 以列出项目,但如何列出代理池?

I'm connecting to VSTS fine like this to list projects for example, but how to list agent pools?

$User = 'mark.allison@domain.com'
$PersonalAccessToken = '{PAT_TOKEN}'
$base64authinfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f  $User, $PersonalAccessToken)))
$vstsAccount = "{VSTS_ACCOUNT}"

# projects
$resource = 'projects'
$uri = "https://sabinio.visualstudio.com/DefaultCollection/_apis/$($resource)?api-version=3.0"
$projects = Invoke-RestMethod -Method Get -ContentType application/json -Uri $Uri -Headers @{Authorization=("Basic {0}" -f $base64authinfo)}

推荐答案

我在官方文档中也没有找到任何相关内容.
但是,通过检查网络流量,我发现了以下内容:https://xyz.visualstudio.com/_apis/distributedtask/pools/ 是获取代理池的方法.
因此,通过 GET 请求,您将获得代理池列表,其中包括名称、ID 和更多属性.如果您使用要删除的池的 ID 向该网址发送 DELETE 请求,它将被删除.
如果一开始要获取代理池的代理,则执行 GET 到:
https://xyz.visualstudio.com/_apis/distributedtask/pools/POOLID/代理
然后,您再次获得该池的代理,其中列出了名称、ID 等.
要删除该代理,您向 https://发送 DELETE 请求xyz.visualstudio.com/_apis/distributedtask/pools/POOLID/agents/AGENTID

I did as well not find anything about it in the official documents.
However by checking the network traffic I figured out the following: https://xyz.visualstudio.com/_apis/distributedtask/pools/ is how to get the Agent Pools.
So with a GET request you will get a list of agent pools, that includes name, id and some more properties. If you send a DELETE request to that url with the ID of the pool you want to delete, it will be removed.
If at first you want to get the agents of an agent pool, you do a GET to:
https://xyz.visualstudio.com/_apis/distributedtask/pools/POOLID/agents
Then again you get the agents of that pool listed with name, id etc.
To delete that agent you send a DELETE request to https://xyz.visualstudio.com/_apis/distributedtask/pools/POOLID/agents/AGENTID

因此,在您的 PowerShell 脚本中,您也不需要获取任何特定于项目的"内容,因为 AgentPools 和 Agents 可用于集合的所有项目.

So in your PowerShell script you as well don't need to fetch anything "project-specific", as the AgentPools and Agents are available for all the projects of the collection.

希望有帮助

这篇关于如何从 PowerShell 以编程方式列出 VSTS 代理池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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