简体   繁体   English

如何使用Azure DevOps REST APi获得构建作业?

[英]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.1https://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.

相关问题 使用REST API获取与Azure Devops中的构建关联的更改 - Get changes associated with a build in Azure Devops using REST API 如何使用 Azure DevOps REST API 创建新的构建管道? - How to create new build pipeline using Azure DevOps REST API? 如何使用 Azure DevOps REST API 对构建进行排队 - How to Queue a Build Using Azure DevOps REST API in Python? 如何使用 Azure DevOps REST API 运行构建/发布管道 - How to run build/release pipeline using Azure DevOps REST API Azure DevOps REST API - 获取作业的代理池? - Azure DevOps REST API - Get agent pools for jobs? 如何使用 Azure DevOps REST ZDB974238714CA8DE634A7CE1DFZ 列出具有部署作业的 YAML 管道? - How to list YAML pipelines with deployment jobs using Azure DevOps REST API? 如何使用 Azure Devops REST API 获取用户所属的团队? - How to get the teams that a user belongs to using Azure Devops REST API? 使用Azure DevOps REST Api,除列出所有内部版本外,如何通过内部版本号获取内部版本? - Using Azure DevOps REST Api how can I get the build by its build number, except by listing all the builds? 如何使用 Azure DevOps REST API 获取 azure devops 发布管道部署日志? - How to get azure devops release pipeline deployment logs using Azure DevOps REST API? How to update azure DevOps build definition source from azure repos to GitHub using rest api - How to update azure DevOps build definition source from azure repos to GitHub using rest api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM