【问题标题】:Azure Devops stage wise build information using rest api not available使用 rest api 的 Azure Devops 阶段性构建信息不可用
【发布时间】:2020-04-24 07:08:45
【问题描述】:

我正在使用 rest api 从 azure devops 收集一些信息。我想获得完整的构建结果,包括每个阶段。但在文档中它不可用。简单的构建 api 调用只能给我有限的数据。有没有办法收集阶段信息,例如阶段是否成功或每个阶段的开始和结束时间。

将不胜感激。

【问题讨论】:

    标签: azure azure-devops continuous-integration devops azure-devops-rest-api


    【解决方案1】:

    你应该先调用这个网址:

    https://dev.azure.com/<YourOrg>/<Your-project>/_apis/build/builds/<buildid>?api-version=5.1
    

    在链接中你会发现时间线:

        "_links": {
            "self": {
                "href": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/Builds/460"
            },
            "web": {
                "href": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_build/results?buildId=460"
            },
            "sourceVersionDisplayUri": {
                "href": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/builds/460/sources"
            },
            "timeline": {
                "href": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/builds/460/Timeline"
            },
            "badge": {
                "href": "https://dev.azure.com/thecodemanual/4fa6b279-3db9-4cb0-aab8-e06c2ad550b2/_apis/build/status/30"
            }
        },
    

    在那里你会找到你要找的东西:

    {
                "previousAttempts": [],
                "id": "67c760f8-35f0-533f-1d24-8e8c3788c96d",
                "parentId": null,
                "type": "Stage",
                "name": "A",
                "startTime": "2020-04-24T08:42:37.2133333Z",
                "finishTime": "2020-04-24T08:42:46.9933333Z",
                "currentOperation": null,
                "percentComplete": null,
                "state": "completed",
                "result": "succeeded",
                "resultCode": null,
                "changeId": 12,
                "lastModified": "0001-01-01T00:00:00",
                "workerName": null,
                "order": 1,
                "details": null,
                "errorCount": 0,
                "warningCount": 0,
                "url": null,
                "log": null,
                "task": null,
                "attempt": 1,
                "identifier": "A"
            },
    

    【讨论】:

      【解决方案2】:

      你也可以参考下面的api,这个rest api是从浏览器的网络中抓取的。

      Get https://dev.azure.com/{org}/{pro}/_build/results?buildId={id}&__rt=fps&__ver=2
      

      阶段结果由不同的数字表示,即 0->已完成、5->已取消等。

      这个api的缺点是返回的内容不能直观的阅读。相比之下,Krzysztof Madej 提供的解决方法更方便直观

      【讨论】:

      • 肯定会结帐。谢谢。
      猜你喜欢
      • 1970-01-01
      • 2019-10-14
      • 2022-07-17
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2020-07-04
      相关资源
      最近更新 更多