[英]How to get the build jobs using Azure DevOps REST APi?
So, I can get the build details, but it does not contain any info on the build jobs. 因此,我可以获得构建详细信息,但其中不包含有关构建作业的任何信息。 Eg Each build job has run on a build agent - how can I get this piece using REST Api? 例如,每个构建作业都在构建代理上运行-如何使用REST Api来获得此代码?
We are talking about a vNext build, not XAML. 我们正在谈论的是vNext版本,而不是XAML。
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 https://dev.azure.com/ {organization} / {project} / _ apis / build / builds / {buildId} /时间线
I use Microsoft.TeamFoundationServer.Client package and this is example for it: 我使用Microsoft.TeamFoundationServer.Client软件包,这是它的示例:
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 https://github.com/ashamrai/TFRestApi/blob/master/19.TFRestApiAppQueueBuild/TFRestApiApp/Program.cs
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) https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}
将让您知道在对象queue
下使用的代理,并在其中显示代理队列(91)的编号和泳池编号(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. https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}?api-version=5.0-preview.1
或https://dev.azure.com/{org}/{project}/_apis/distributedtask/queues/{queue_id}
将返回池。
So now using https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents
will return a LIST of agents under the Agent Pools 因此,现在使用https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents
将在“代理程序池”下返回代理程序列表
Now that I've explained all that let's try to tie everything together. 现在,我已经解释了所有这些,让我们尝试将所有内容捆绑在一起。
1) Use https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}
and find the Queue and Pool IDs. 1)使用https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}
并找到队列和池ID。
2) 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. 2)使用https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}/timeline
并找到Job
类型的记录和属性workerName
,这些记录将返回代理的名称用过的。
3) 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. 3)使用https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents
查询代理,并通过从上面步骤2中找到的名称中过滤name
来查找代理id
。
4) 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. 4)最后查询https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents/{agent_id}
将返回代理的高级信息,而不是很多信息。
This next api is undocumented 下一个api未记录
5) To get the detailed capabilities query https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents/{agent_id}?includeCapabilities=true
which a huge result set will be returned!! 5)要获取详细功能,请查询https://dev.azure.com/{org}/_apis/distributedtask/pools/{pool_id}/agents/{agent_id}?includeCapabilities=true
,这将返回巨大的结果集! ! I think this is what you want. 我想这就是你想要的。
Read more about the APIs at: 在以下网址了解有关API的更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.