Skip to content

Instantly share code, notes, and snippets.

@ryanvgates
Last active September 16, 2016 04:06
Show Gist options
  • Save ryanvgates/446f6059efd52ee44859 to your computer and use it in GitHub Desktop.
Save ryanvgates/446f6059efd52ee44859 to your computer and use it in GitHub Desktop.
TFS PSM
#
# TFS.psm1
#
Function QueueBuilds {
param($serverName, $teamProject, [string[]]$buildDefinitionNames)
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
$serverName=$serverName
$teamProject=$teamProject
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
foreach($buildDefinitionName in $buildDefinitionNames) {
Write-Output "Queuing build $buildDefinitionName"
$buildDefinition = $buildserver.GetBuildDefinition($teamProject, $buildDefinitionName)
$buildRequest = $buildDefinition.CreateBuildRequest();
Write-Output $buildRequest
$result = $buildserver.QueueBuild($BuildReq)
}
}
Export-ModuleMember -Function 'QueueBuilds'
@Taiwo1
Copy link

Taiwo1 commented Sep 16, 2016

This is still broken. Use this:
Function QueueBuilds {
param($serverName, $teamProject, [string[]]$buildDefinitionNames)

   [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
   [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

   $serverName=$serverName
   $teamProject=$teamProject
   $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
   $buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])

   foreach($buildDefinitionName in $buildDefinitionNames) {
          Write-Output "Queuing build $buildDefinitionName"
          $buildDefinition = $buildserver.GetBuildDefinition($teamProject, $buildDefinitionName)
          $buildRequest = $buildDefinition.CreateBuildRequest();
          Write-Output $buildRequest
          $result = $buildserver.QueueBuild($buildRequest, "None")
   }

}

Export-ModuleMember -Function 'QueueBuilds'

Works a lot better. You got us 90% of the way there and thanks but please test your code. I'm not a Powershell guy.

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