0

I am using rest api to gather some information from azure devops. I want to get full build results including every stage. But in the documentation it is not available. The simple build api call only gives me limited data. Is there any way to collect the stage wise information like whether the stage was successful or the start and end time for each stage.

Will be grateful for the help.

2 Answers2

3

You should first call this url:

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

in links you will find timeline:

    "_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"
        }
    },

and there you will find what you are looking for:

{
            "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"
        },
Krzysztof Madej
  • 32,704
  • 10
  • 78
  • 107
0

You can also refer to the below api, this rest api is grabbed from the browser's Network.

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

enter image description here

Stage results are represented by different numbers i.e 0->completed,5->canceled etc.

The disadvantage of this api is that the returned content cannot be read intuitively. In contrast, the workaround provided by Krzysztof Madej is more convenient and intuitive

Hugh Lin
  • 17,829
  • 2
  • 21
  • 25