Thursday, September 21, 2017

Rest API call to TFS to get the changeset details from the build


Getting the changeset details from VSTS

Enable the setting "Allow script to access OAuth token" in the VSTS team system and run the following powershell commands


$buildId = $env:BUILD_BUILDID

$headers = @{Authorization=("Bearer {0}" -f $env:SYSTEM_ACCESSTOKEN)}

$buildInfoUri = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)$env:SYSTEM_TEAMPROJECTID/_apis/build/builds/$($buildId)?api-version=2.0"

$buildInfo = Invoke-RestMethod -Method Get -Uri $buildInfoUri -Headers $headers 

$sourceVersion = $buildInfo.sourceVersion

$changesetUrl = "$($env:SYSTEM_TEAMFOUNDATIONCOLLECTIONURI)/_apis/tfvc/changesets/$($sourceVersion)/changes?api-version=2.0"

$changeset = Invoke-RestMethod -Method Get -Uri $changesetUrl -Headers $headers 

No comments:

Post a Comment