Just a small followup on Getting latest build in PS as the link is related to vNext build.
But what about the old XAML build, if you still have this?
Here we use the version 1.0 of the REST API and it is quite simple:
First the usual constants:
$tfsServerURL = "HTTP://fabrikam:8080/tfs/defaultcollection"
$TFSProject = "My project"
$BuildDefinition = "MyAwesomeBuild"
$URL = "$($tfsServerURL)/$($TFSProject)"
Then call the REST interface:
(Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?api-version=1.0&definition=' + $BuildDefinition) -Method GET -UseDefaultCredentials).value
If you want to get the latest succeeded build, just add the Status paramter.
(Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?api-version=1.0&definition=' + $BuildDefinition +'&status=Succeeded&$top=1') -Method GET -UseDefaultCredentials).value
Full script:
$tfsServerURL = "HTTP://fabrikam:8080/tfs/defaultcollection" $TFSProject = "My project" $BuildDefinition = "MyAwesomeBuild" $URL = "$($tfsServerURL)/$($TFSProject)" #Get the specific Build (Invoke-RestMethod -Uri ($URL + '/_apis/build/builds?api-version=1.0&definition=' + $BuildDefinition +'&status=Succeeded&$top=1') -Method GET -UseDefaultCredentials).value
Documentation is available here: XAML build