azure-devops-dotnet-samples icon indicating copy to clipboard operation
azure-devops-dotnet-samples copied to clipboard

BuildHttpClient.GetQueuesAsync() missing in API version 15

Open HeinerMichael opened this issue 5 years ago • 4 comments

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

HeinerMichael avatar Jan 29 '19 12:01 HeinerMichael

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.

vbtrek avatar Feb 03 '20 11:02 vbtrek

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

HeinerMichael avatar Feb 03 '20 13:02 HeinerMichael

I would like to have the functionality as well.

smaglio81 avatar Oct 29 '20 16:10 smaglio81

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

quintessential5 avatar Oct 30 '20 23:10 quintessential5