Search code examples
azure-devopsazure-devops-rest-apiazure-devops-server-2019

Azure DevOps: Can we identify Builds triggered from a changeset number?


I have certain builds set for Continuous Integration, i.e., build for every check-in. I have an automated method to perform code merge and check-ins; now I want to get the list of builds triggered for a particular changeset created. Is there any way we could get this information?


Solution

  • I would use the the REST API so you could check for builds that were run:

    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds
    

    will return all builds that you could then go through and check for more details. You can also have more filters in the request (for example based on the build definition).

    The build specifics you could then get via:

    GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/<buildid>
    

    This will return you the infos like:

    "triggerInfo": {
        "ci.sourceBranch": "refs/heads/master",
        "ci.sourceSha": "0fcb5a27ca2f73561dde0a066a1ec1781128fa81",
        "ci.message": ""
    },
    ...
    "sourceBranch": "refs/heads/master",
    "sourceVersion": "0fcb5a27ca2f73561dde0a066a1ec1781128fa81",
    

    for builds queued from a git repository or

    { ...
      "sourceBranch": "$/Build Test",
      "sourceVersion": "93",
    ... }
    

    for TFVC repositories. It actually also would contain a trigger info but I don't have any build around that was triggered automatically based on TFVC.

    The sourceVersion in git will be the commit hash, where in TFVC it's the changeset.

    More details on the REST API can be found in the Microsoft Docs