Search code examples
visual-studiopowershelltfsbuildazure-devops

VSTS build RestAPI retrieve changesets from last successful or partial successful build


I'm using RESTAPI in a PowerShell script to retrieve all changesets since the last successful build, which is called in a vNext VSTS build step.

$TfsUrl = 'https://' + $Account + '.visualstudio.com/defaultcollection/' + $ProjectName

$CurrentBuildUrl = $TfsUrl + "/_apis/build/builds?api-version=2.0"+ "&definitions=" + $BuildDefinitionID + "&`$top=1"

$CurrentBuildDef = Invoke-RestMethod -Uri $CurrentBuildUrl -Headers $Headers -Method Get

$BuildId = $CurrentBuildDef.value.id

$BaseUrl =  "https://" + $Account + ".visualstudio.com/defaultcollection/_apis/tfvc/changesets"
$ChangeSetHistoryUrl = $TfsUrl + "/_apis/build/builds/$BuildId/changes?api-version=2.0"
$ChangeSetsHistoryDef = (Invoke-RestMethod -Uri $ChangeSetHistoryUrl -Headers $Headers -Method Get).value

Then I loop through the the changesets and write details to a file.

This works ok when I have a successful build.
It doesn't work when I have a partial successful build i.e. Some Constraint Tests Failed.

It includes all changesets from the successful build instead of since the latest partial successful build.

I would like to retrieve all changesets since the last successful or partial successful build, whichever was last.

Is this possible?


Solution

  • No, there isn't any way to do this for now. The "get build changes" api always compare to the last successfully build to get the changes in current build. There isn't any option to set it to compare with the last build no matter the build status is success or partial success. You can submit a feature request for this on VSTS User Voice.