如何使用TFS REST API获取正在运行的构建的进度?

时间:2017-06-11 06:11:44

标签: tfs tfs-sdk

我在TFS& amp; VSTS,并想知道如何获得正在运行的构建或发布的整体进度(百分比)。

1 个答案:

答案 0 :(得分:1)

您可以将Rest API Get build details与时间轴一起使用。

GET https://{instance}/DefaultCollection/{project}/_apis/build/builds/{buildId}/timeline?api-version={version}

这将返回构建时间轴和一些更详细的信息,包括 percentComplete 结果。注意:这是基于任务级别的,就像webportal中的构建日志一样,而不是整个构建。

示例回复

{
  "records": [
    {
      "id": "bcddc27d-c891-4209-85d6-387e155439b0",
      "parentId": "045f4ce9-cb71-424f-84de-4ab19281dc70",
      "type": "Task",
      "name": "Build solution **\\*.sln",
      "startTime": "2015-07-16T19:53:20.853Z",
      "finishTime": "2015-07-16T19:53:28.567Z",
      "currentOperation": null,
      "percentComplete": 100,
      "state": "completed",
      "result": "succeeded",
      "resultCode": null,
      "changeId": 16,
      "lastModified": "0001-01-01T00:00:00",
      "workerName": "Hosted Agent",
      "order": 2,
      "details": {
        "id": "ef959107-e566-4c28-8d9f-354d605dd400",
        "changeId": 6,
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c/_apis/build/builds/391/Timeline/ef959107-e566-4c28-8d9f-354d605dd400"
      },
      "errorCount": 0,
      "warningCount": 1,
      "url": null,
      "log": {
        "id": 2,
        "type": "Container",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c/_apis/build/builds/391/logs/2"
      },
      "issues": [
        {
          "type": "warning",
          "category": "General",
          "message": "The MSBuild version parameter has been deprecated. Ignoring value: latest",
          "data": {
            "type": "warning"
          }
        }
      ]
    },
    {
      "id": "b5bb4de7-a8ea-4c7d-8491-3f745bba7d1b",
      "parentId": "045f4ce9-cb71-424f-84de-4ab19281dc70",
      "type": "Task",
      "name": "Get sources",
      "startTime": "2015-07-16T19:53:07.057Z",
      "finishTime": "2015-07-16T19:53:19.493Z",
      "currentOperation": null,
      "percentComplete": 100,
      "state": "completed",
      "result": "succeeded",
      "resultCode": null,
      "changeId": 13,
      "lastModified": "0001-01-01T00:00:00",
      "workerName": "Hosted Agent",
      "order": 1,
      "details": null,
      "errorCount": 0,
      "warningCount": 0,
      "url": null,
      "log": {
        "id": 1,
        "type": "Container",
        "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/6ce954b1-ce1f-45d1-b94d-e6bf2464ba2c/_apis/build/builds/391/logs/1"
      }
    },

enter image description here