Azure DevOps API to access Multi Repo Sources of a Build

Viewed 187

I have a YAML Build Definition that uses multiple repos.

When looking at the Build Results, there is a "Sources" Card that lists the Repos and the commit ID that was used for this particular build. I tried looking through all the api documentation for this info, but I can't seem to find it easily. I took a look at the Get Build call, but that just gives the Main Repo used.

Does anyone know the API well enough to point me to the api call to access that set of Data that contains the repos/resources and their commit ids ?

Thanks!

2 Answers

You can use the following REST API:

GET https://dev.azure.com/{Organization}/{Project}/_build/results?buildId={Build ID}&__rt=fps&__ver=2

Its response body is quite massive, the information about multiple repositories is in:

fps -> dataProviders -> data -> ms.vss-build-web.run-details-data-provider -> repositoryResources

It shows all source repositories including their names, ids, versions, and so on.

This REST API is not documented and I get it from Developer Tools. Most of the information contained in it is web page information.

It looks that this is not available over REST API (yet). However, this is really strange, because if you hit get build endpoint:

https://dev.azure.com/{{organization}}/{{project}}/_apis/build/builds/826?api-version=6.0-preview.6&expand=all

in link section you will find sourceVersionDisplayUri

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

but the URL redirects you to commit which actually trigerred a build.

It still possible to get commits and repos from the logs

https://dev.azure.com/{{organization}}/{{project}}/_apis/build/builds/826/logs/6?api-version=6.0-preview.2

But for that you need to get trough them and parse responses:

2020-05-08T11:13:04.3354990Z Syncing repository: kmadof/devops-templates (github)
.
.
.
.

2020-05-08T11:13:03.3810662Z ##[command]git checkout --progress --force 24602dc40710a53502d306d1d41d3bca3c9a9b80
2020-05-08T11:13:03.3816465Z Note: switching to '24602dc40710a53502d306d1d41d3bca3c9a9b80'.
2020-05-08T11:13:05.1455197Z ##[command]git checkout --progress --force 0d79e869239bbf0087492ac2cda3a59e9ef11a39
2020-05-08T11:13:05.1458382Z Note: switching to '0d79e869239bbf0087492ac2cda3a59e9ef11a39'.
Related