public static List <AgentPool> GetAgentPools() { var agentPools = new List <AgentPool>(); using (var response = httpClient.GetAsync($"{baseUrl}/_apis/distributedtask/pools").Result) { response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsStringAsync().Result; var jObject = JObject.Parse(responseBody); foreach (var agentPoolJson in jObject["value"]) { var agentPool = new AgentPool { Id = agentPoolJson["id"].ToString(), Name = agentPoolJson["name"].ToString() }; var agents = GetAgentsInPool(agentPool); agentPool.Agents = agents; agentPools.Add(agentPool); } } return(agentPools); }
public static List <Agent> GetAgentsInPool(AgentPool pool) { var agents = new List <Agent>(); using (var response = httpClient.GetAsync($"{baseUrl}/_apis/distributedtask/pools/{pool.Id}/agents?includeCapabilities=true").Result) { response.EnsureSuccessStatusCode(); string responseBody = response.Content.ReadAsStringAsync().Result; var jObject = JObject.Parse(responseBody); foreach (var agentsJson in jObject["value"]) { var agent = new Agent { Id = agentsJson["id"].ToString(), Name = agentsJson["systemCapabilities"]["Agent.Name"].ToString(), Version = agentsJson["version"].ToString(), Enabled = agentsJson["enabled"].ToString(), Status = agentsJson["status"].ToString(), /* * "id": 4, * "name": "R5EBUILDAGENT02", * "version": "2.134.2", * "osDescription": "Microsoft Windows 10.0.14393 ", * "enabled": true, * "status": "offline", * * "Agent.Name": "vststestAgt1", * "Agent.Version": "2.134.2", * "Agent.ComputerName": "R5EBUILDAGENT02", * "Agent.HomeDirectory": "C:\\vststestAgt1", * "Agent.OS": "Windows_NT", * "Agent.OSVersion": "10.0.14393", */ }; var capabilities = agentsJson["systemCapabilities"]; if (capabilities["Agent.ComputerName"] != null) { agent.ComputerName = agentsJson["systemCapabilities"]["Agent.ComputerName"].ToString(); } if (capabilities["Agent.HomeDirectory"] != null) { agent.HomeDirectory = agentsJson["systemCapabilities"]["Agent.HomeDirectory"].ToString(); } if (capabilities["Agent.OS"] != null) { agent.OS = agentsJson["systemCapabilities"]["Agent.OS"].ToString(); } if (capabilities["Agent.OSVersion"] != null) { agent.OSVersion = agentsJson["systemCapabilities"]["Agent.OSVersion"].ToString(); } agents.Add(agent); } } return(agents); }