Reputation: 62712
So, I can get the build details, but it does not contain any info on the build jobs. E.g. Each build job has run on a build agent - how can I get this piece using REST Api?
We are talking about a vNext build, not XAML.
Upvotes: 3
Views: 4844
Reputation: 15988
You can find all tasks and jobs in timeline records: Timeline - Get. You can paste into browser this template to check results for a specific build:
https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline
I use Microsoft.TeamFoundationServer.Client package and this is example for it:
static void PrintTimeLine(string TeamProjectName, int BuildId)
{
var timeline = BuildClient.GetBuildTimelineAsync(TeamProjectName, BuildId).Result;
if (timeline.Records.Count > 0)
{
Console.WriteLine("Task Name-----------------------------Start Time---Finish Time---Result");
foreach(var record in timeline.Records)
if (record.RecordType == "Task")
Console.WriteLine("{0, -35} | {1, -10} | {2, -10} | {3}",
(record.Name.Length < 35) ? record.Name : record.Name.Substring(0, 35),
(record.StartTime.HasValue) ? record.StartTime.Value.ToLongTimeString() : "",
(record.FinishTime.HasValue) ? record.FinishTime.Value.ToLongTimeString() : "",
(record.Result.HasValue) ? record.Result.Value.ToString() : "");
}
}
https://github.com/ashamrai/TFRestApi/blob/master/19.TFRestApiAppQueueBuild/TFRestApiApp/Program.cs
Upvotes: 6
Reputation: 1781
https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}
will let you know the Agent used under the object queue
and there it shows the agent queue (91) number and the pool id (8)
"queue":{
"id":91,
"name":"MotBuild-Default",
"pool":{
"id":8,
"name":"MotBuild-Default"
}
Use
https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}?api-version=5.0-preview.1
or https://dev.azure.com/{org}/{project}/_apis/distributedtask/queues/{queue_id}
will return the pool.
So now using https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents
will return a LIST of agents under the Agent Pools
Now that I've explained all that let's try to tie everything together.
Use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}
and find the Queue and Pool IDs.
use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline
and find the record of type Job
and the property workerName
which will return NAME of the Agent used.
Query the Agents with https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents
and find the agent id
by filtering the name
from the name found in step #2 above.
Finally query https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents/{agent_id}
will return a high-level info of the agent, not much info.
This next api is undocumented
https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents/{agent_id}?includeCapabilities=true
which a huge result set will be returned!! I think this is what you want.Read more about the APIs at:
Upvotes: 3