如何查找正在进行的TFS版本?

时间:2018-06-29 02:00:18

标签: powershell tfs build queue release

如果TFS 2018的管道未完全完成,我需要使它失败。仅批处理构建是不够的。必须先完成链接的发行版,然后才能开始另一个构建。我的想法是通过REST API在PowerShell脚本中执行此操作。

我在官方文档here中看到有一个名为TaskStatus的属性。它提供的值为inProgress,大概是针对正在进行的发行。这也许可以解决问题,但是没有指示如何实际使用它。

使用REST API,如何获得给定版本的TaskStatus

1 个答案:

答案 0 :(得分:0)

in process和其他一些值,例如succeededcanceled代表发布管道中任务的状态。

您只需使用Rest API即可获得发布

GET https://fabrikam.vsrm.visualstudio.com/MyFirstProject/_apis/release/releases/{releaseId}?api-version=4.1-preview.6

应该有一个名为status的值:

"id": 18,
  "name": "Release-18",
  "status": "abandoned",
  "createdOn": "2017-06-16T01:36:20.397Z",
  "modifiedOn": "2017-06-16T01:36:21.07Z",
  "modifiedBy": {
    "id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
    "displayName": "Chuck Reinhart",
    "uniqueName": "fabfiber@outlook.com",
    "url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
    "imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
  },
  "createdBy": {
    "id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
    "displayName": "Chuck Reinhart",
    "uniqueName": "fabfiber@outlook.com",
    "url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
    "imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
  },
  "environments": [
    {
      "id": 69,
      "releaseId": 18,
      "name": "Dev",
      "status": "notStarted",
      "variables": {},
      "preDeployApprovals": [],
      "postDeployApprovals": [],
      "preApprovalsSnapshot": {
        "approvals": [
          {
            "rank": 1,
            "isAutomated": false,
            "isNotificationOn": false,
            "approver": {
              "id": "4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
              "displayName": "Chuck Reinhart",
              "uniqueName": "fabfiber@outlook.com",
              "url": "https://app.vssps.visualstudio.com/A168224e4-29ff-4081-9954-c8780ce81117/_apis/Identities/4adb1680-0eac-6149-b5ee-fc8b4f6ca227",
              "imageUrl": "https://fabfiber-inc.visualstudio.com/_api/_common/identityImage?id=4adb1680-0eac-6149-b5ee-fc8b4f6ca227"
            },
            "id": 0
          }

您可以在返回的json文件中获取值状态,并判断发布是成功还是失败。最后根据此状态触发另一个构建。


更新

返回的json的示例,其中包含任务的状态信息:

  "deploymentJobs": [
                                {
                                    "job": {
                                        "id": 5,
                                        "timelineRecordId": "855ea6d6-9ed0-442d-b921-0c4add8bb068",
                                        "name": "Release",
                                        "dateStarted": "2018-07-04T08:53:05.9133333Z",
                                        "dateEnded": "2018-07-04T08:53:21.34Z",
                                        "startTime": "2018-07-04T08:53:05.9133333Z",
                                        "finishTime": "2018-07-04T08:53:21.34Z",
                                        "status": "succeeded",
                                        "rank": 1,
                                        "issues": [],
                                        "agentName": "DFA00"
                                    },
                                    "tasks": [
                                        {
                                            "id": 1,
                                            "timelineRecordId": "fa3bb635-eab4-4c1b-9cc0-fdccd7ced33f",
                                            "name": "Initialize Job",
                                            "dateStarted": "2018-07-04T08:53:06.5833333Z",
                                            "dateEnded": "2018-07-04T08:53:06.8033333Z",
                                            "startTime": "2018-07-04T08:53:06.5833333Z",
                                            "finishTime": "2018-07-04T08:53:06.8033333Z",
                                            "status": "succeeded",
                                            "rank": 1,
                                            "issues": [],
                                            "agentName": "DFA00",
                                            "logUrl": "http://xxxx:8080/tfs/DefaultCollection/7658559e-6e61-422a-952b-a5fce0b6ca1d/_apis/Release/releases/49/environments/49/tasks/1/logs?releaseDeployPhaseId=54"
                                        }, 

对于单个发布中的任务部署结果,应该有时间轴记录开始时间结束时间状态