azure-devops-dotnet-samples
azure-devops-dotnet-samples copied to clipboard
BuildHttpClient.GetQueuesAsync() missing in API version 15
Hi, in order to create build definitions and to queue builds programmatically, I need to specify a build definition member "Queue" of type "AgentPoolQueue". In Version 14 of VSTS API there was a function called "GetQueuesAsync" that returned a list of AgentPoolQueue objects. In Version 15 this function is missing. Is there an alternate way to retrieve the agent pool queues? Thanks in advance Michael
I'm also looking for something similar to this, I want to get a list of Pools linked to a project, and subsequently a count of agents within each pool.
Hi vbtrek, by now I didn't find any methode like 'GetQueuesAsync()'. So I decided to use a REST call. In tfs team projects agent pools are represented by agent queues. I used following function to retrieve a specific agent queue:
public AgentPoolQueue GetBuildQueue(string project, string queueName)
{
AgentPoolQueue apQueue = null;
HttpClientHandler authtHandler = new HttpClientHandler()
{
Credentials = CredentialCache.DefaultNetworkCredentials
};
using (HttpClient client = new HttpClient(authtHandler))
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string restString = $"{CollectionUrl}/{project}/_apis/distributedtask/queues?actionFilter=16";
using (HttpResponseMessage response = client.GetAsync(restString).Result)
{
response.EnsureSuccessStatusCode();
var jResult = response.Content.ReadAsStringAsync().Result;
JObject jObject = JObject.Parse(jResult);
List<AgentPoolQueue> queues = JsonConvert.DeserializeObject<List<AgentPoolQueue>>(jObject["value"].ToString());
if (queues != null)
{
foreach (var queue in queues)
{
if (queue.Name.Equals(queueName, StringComparison.InvariantCultureIgnoreCase))
{
apQueue = queue;
break;
}
}
}
}
}
return apQueue;
}
If you need direct access to the pools, you should use the 'TaskAgentHttpClient' like this:
TaskClient = Connection.GetClient<TaskAgentHttpClient>(); public List<TaskAgentPool> GetAgentPools() { return TaskClient.GetAgentPoolsAsync().Result; }
I hope that helps! Michael
I would like to have the functionality as well.
Looks like they moved it to TaskAgentHttpClient
https://docs.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.distributedtask.webapi.taskagenthttpclientbase.getagentqueuesasync?view=azure-devops-dotnet