Sunday, 18 August 2013

Powershell Script for TFS Build Definition

Powershell Script for TFS Build Definition

I am trying to create a powershell script to create TFS build definition.
I this example in C# to create it
(http://geekswithblogs.net/jakob/archive/2010/04/26/creating-a-build-definition-using-the-tfs-2010-api.aspx).
However, I am having trouble creating a build definition.
My Script:
param(
[Parameter(Mandatory=$true)]
[string] $buildName,`enter code here`
[string] $teamProject="Templates",
[string] $buildTemplateName = "TestBuildTemplate",
[string] $buildDescription = "Test Descirption",
[string] $buildController = "TFS - Controller"
)
Clear-Host
$ErrorActionPreference = "Stop" ;
if ($Verbose) { $VerbosePreference = "Continue" ; }
$assemblylist =
"Microsoft.TeamFoundation.Build.Client",
"Microsoft.TeamFoundation.Build.Workflow",
"Microsoft.TeamFoundation.Client",
"Microsoft.TeamFoundation.Common",
"Microsoft.TeamFoundation.WorkItemTracking.Client"
Write-Verbose -Message "Loading TFS Build assembly…"
foreach ($asm in $assemblylist)
{
$asm = [Reflection.Assembly]::LoadWithPartialName($asm)
}
$tfsCollectionUrl = "TFS Server IP Address"
$server.EnsureAuthenticated()
if(!$server.HasAuthenticated)
{
Write-Host "Failed to authenticate TFS"
exit
}
Write-Host "Connected to TFS...."
$buildServer =
$server.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$def = $buildserver.CreateBuildDefinition($teamProject)
$def.Name = $buildTemplateName
$def.Description = $buildDescription
$def.Workspace.AddMapping("$/Default/Sampleapplication1",
'"$(SourceDir)"', 0)
$def.Workspace.AddMapping('"$/OtherPath/"', "", 1)
$def.BuildController = $buildserver.GetBuildController($buildController)
$def.DefaultDropLocation = "Drop Location Share"
enter code here
Write-Host "Get default template...."
$def.Save()
The error i am getting is unable to save as Process is not defined. What I
am I missing here?

No comments:

Post a Comment