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

查看:71
本文介绍了如何从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向该URL发送DELETE请求,则该请求将被删除.
如果起初要获取代理程序池的代理程序,请执行GET到:
https://xyz.visualstudio.com/_apis/distributedtask/pools/POOLID/代理商
然后再次获得列出该池的代理的名称,标识等.
要删除该代理,请向 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天全站免登陆