Skip to content

Instantly share code, notes, and snippets.

@adamskt
Last active October 5, 2015 22:58
Show Gist options
  • Save adamskt/2891859 to your computer and use it in GitHub Desktop.
Save adamskt/2891859 to your computer and use it in GitHub Desktop.
A way to get the latest successful drop location from a TFS build.
Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
Add-Type -AssemblyName "Microsoft.TeamFoundation.Build.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
$tfsUri = New-object Uri("[[http://your.tfs.server:8080/defaultcollection]]")
$teamProjectCollection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsUri)
$service = $teamProjectCollection.GetService([Type]"Microsoft.TeamFoundation.Build.Client.IBuildServer")
$spec = $service.CreateBuildDetailSpec("[[Your Project Name]]", "[[ Your build definition name]]")
$spec.MaxBuildsPerDefinition = 1
$spec.QueryOrder = [Microsoft.TeamFoundation.Build.Client.BuildQueryOrder]::FinishTimeDescending
$spec.Status = [Microsoft.TeamFoundation.Build.Client.BuildStatus]::Succeeded
$results = $service.QueryBuilds($spec)
if ($results.Builds.Length -eq 1) { $results.Builds[0].DropLocation } else { Write-Error "No builds found." }
@adamskt
Copy link
Author

adamskt commented Jun 7, 2012

This should work with TFS2010, just change the Add-Type references.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment