XamlBuild/XamlBuild.psm1
Function Get-TfsXamlBuildAgent { [CmdletBinding()] [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildAgent])] Param ( [Parameter(Position=0)] [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent]})] [ValidateNotNullOrEmpty()] [Alias("Name")] [object] $BuildAgent = "*", [Parameter(Position=0, ValueFromPipeline=$true)] [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})] [ValidateNotNullOrEmpty()] [Alias("Controller")] [object] $BuildController = "*", [Parameter()] [object] $Collection ) Process { if ($BuildAgent -is [Microsoft.TeamFoundation.Build.Client.IBuildAgent]) { return $BuildAgent } $controllers = Get-TfsXamlBuildController -BuildController $BuildController -Collection $Collection foreach($controller in $controllers) { $controller.Agents | Where Name -Like $BuildAgent } } } Function Get-TfsXamlBuildController { [CmdletBinding()] [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildController])] Param ( [Parameter(Position=0)] [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildController]})] [ValidateNotNullOrEmpty()] [Alias("Name")] [object] $BuildController = "*", [Parameter(ValueFromPipeline=$true)] [object] $Collection ) Process { if ($BuildController -is [Microsoft.TeamFoundation.Build.Client.IBuildController]) { return $BuildController } $tpc = Get-TfsTeamProjectCollection $Collection $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer') $buildControllers = $buildServer.QueryBuildControllers() return $buildControllers | Where Name -Like $BuildController } } <# .SYNOPSIS Gets all queued builds .PARAMETER BuildDefinition Uses this parameter to filter for an specific Build Defintion. If suppress, cmdlet will show all queue builds. .PARAMETER Collection Specifies either�a�URL�or�the�name�of�the�Team�Project�Collection�to�connect�to,�or�a�previously�initialized�TfsTeamProjectCollection�object. For�more�details,�see�the�-Collection�argument�in�the�Get-TfsTeamProjectCollection�cmdlet. .PARAMETER Project Specifies either the�name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to.� For�more�details,�see�the�-Project�argument�in�the�Get-TfsTeamProject�cmdlet. .EXAMPLE Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project" Get all queued builds given a definition name and a team project name .EXAMPLE Get-TfsBuildQueue Get all queued builds, regardless of definition name or team project name #> Function Get-TfsXamlBuildDefinition { [CmdletBinding()] [OutputType([Microsoft.TeamFoundation.Build.Client.IBuildDefinition])] Param ( [Parameter(Position=0)] [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})] [ValidateNotNullOrEmpty()] [Alias("Name")] [object] $BuildDefinition = "*", [Parameter(ValueFromPipeline=$true)] [object] $Project, [Parameter()] [object] $Collection ) Process { if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]) { return $BuildDefinition } $tp = Get-TfsTeamProject $Project $Collection $tpName = $tp.Name $tpc = $tp.Store.TeamProjectCollection $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer') $buildDefs = $buildServer.QueryBuildDefinitions($tpName) return $buildDefs | Where Name -Like $BuildDefinition } } <# .SYNOPSIS Gets all queued builds .PARAMETER BuildDefinition Uses this parameter to filter for an specific Build Defintion. If suppress, cmdlet will show all queue builds. .PARAMETER Collection Specifies either�a�URL�or�the�name�of�the�Team�Project�Collection�to�connect�to,�or�a�previously�initialized�TfsTeamProjectCollection�object. For�more�details,�see�the�-Collection�argument�in�the�Get-TfsTeamProjectCollection�cmdlet. .PARAMETER Project Specifies either the�name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to.� For�more�details,�see�the�-Project�argument�in�the�Get-TfsTeamProject�cmdlet. .EXAMPLE Get-TfsBuildQueue -BuildDefinition "My Build Definition" -Project "My Team Project" Get all queued builds given a definition name and a team project name .EXAMPLE Get-TfsBuildQueue Get all queued builds, regardless of definition name or team project name #> Function Get-TfsXamlBuildQueue { [CmdletBinding()] [OutputType([Microsoft.TeamFoundation.Build.Client.IQueuedBuild])] Param ( [Parameter(Position=0, ValueFromPipeline=$true)] [ValidateScript({$_ -is [string] -or $_ -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]})] [ValidateNotNullOrEmpty()] [object] $BuildDefinition = "*", [Parameter()] [object] $Project, [Parameter()] [object] $Collection ) Process { if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]) { $buildDefName = $BuildDefinition.Name } else { $buildDefName = $BuildDefinition } if ($Project) { $tp = Get-TfsTeamProject $Project $Collection $tpName = $tp.Name $tpc = $tp.Store.TeamProjectCollection } else { $tpName = "*" $tpc = Get-TfsTeamProjectCollection $Collection } $buildServer = $tpc.GetService([type]'Microsoft.TeamFoundation.Build.Client.IBuildServer') $query = $buildServer.CreateBuildQueueSpec($tpName, $buildDefName) $buildServer.QueryQueuedBuilds($query).QueuedBuilds } } <# .SYNOPSIS Queues a new XAML Build. .PARAMETER BuildDefinition Build Definition Name that you want to queue. .PARAMETER Collection Specifies either�a�URL�or�the�name�of�the�Team�Project�Collection�to�connect�to,�or�a�previously�initialized�TfsTeamProjectCollection�object. For�more�details,�see�the�-Collection�argument�in�the�Get-TfsTeamProjectCollection�cmdlet. .PARAMETER Project Specifies either the�name of the Team Project or a previously initialized Microsoft.TeamFoundation.WorkItemTracking.Client.Project object to connect to.� For�more�details,�see�the�-Project�argument�in�the�Get-TfsTeamProject�cmdlet. .EXAMPLE Start-TfsBuild -BuildDefinition "My Build Definition" -Project "MyTeamProject" This example queue a Build Definition "My Build Definition" of Team Project "MyTeamProject". #> Function Start-TfsXamlBuild { Param ( [Parameter(Mandatory=$true, Position=0)] [object] $BuildDefinition, [Parameter(ValueFromPipeline=$true, Mandatory=$true)] [object] [ValidateNotNull()] [ValidateScript({($_ -is [string]) -or ($_ -is [Microsoft.TeamFoundation.WorkItemTracking.Client.Project])})] $Project, [Parameter()] [object] $Collection, [Parameter()] [string] [ValidateSet("LatestOnQueue", "LatestOnBuild", "Custom")] $GetOption = "LatestOnBuild", [Parameter()] [string] $GetVersion, [Parameter()] [string] $DropLocation, [Parameter()] [hashtable] $Parameters ) Process { $tp = Get-TfsTeamProject $Project $Collection $tpc = $tp.Store.TeamProjectCollection $buildServer = $tpc.GetService([type]"Microsoft.TeamFoundation.Build.Client.IBuildServer") if ($BuildDefinition -is [Microsoft.TeamFoundation.Build.Client.IBuildDefinition]) { $buildDef = $BuildDefinition } else { $buildDef = $buildServer.GetBuildDefinition($tp.Name, $BuildDefinition); } $req = $buildDef.CreateBuildRequest() $req.GetOption = [Microsoft.TeamFoundation.Build.Client.GetOption] $GetOption; if ($GetOption -eq "Custom") { $req.CustomGetVersion = $GetVersion } if ($DropLocation) { $req.DropLocation = $DropLocation } $buildServer.QueueBuild($req) } } |