用于生成TFS定义的PowerShell脚本



我正在尝试创建一个PS脚本来创建TFS构建定义文件。我发现下面的例子。但是,它不能正常工作。我试图效仿这个例子,创建一个脚本,但没有成功。感谢您在确定以下脚本不起作用的原因方面提供的任何帮助,以及如何创建PS脚本或示例的指导

param(
             [Parameter(Mandatory=$true)]
             [string] $buildName,
        [string] $serverName="http://tfs:80/",
        [string] $teamProject="MyProject"
)
# VS 2010
# $tfsClientVersion = ", Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
# VS 2008
$tfsClientVersion = ", Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
[void][System.Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client"+$tfsClientVersion)
[void][System.Reflection.Assembly]::Load("Microsoft.TeamFoundation.Build.Client"+$tfsClientVersion)
[void][System.Reflection.Assembly]::Load("Microsoft.TeamFoundation.VersionControl.Client"+$tfsClientVersion)
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName) 
$versionControl = $tfs.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer]) 
$buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
$def = $buildserver.CreateBuildDefinition($teamProject)
$def.Name = "$buildName"
$def.Description = "Created by Powershell script "
$agentSpec = $buildServer.CreateBuildAgentSpec($teamProject)
$agentSpec.Name = "build"
$agent = $buildServer.QueryBuildAgents($agentSpec).Agents[0]
$def.DefaultBuildAgent = $agent
$def.DefaultDropLocation = "\buildPrivateDrops"
$def.RetentionPolicies.Item('Failed').NumberToKeep = 5
$def.RetentionPolicies.Item('Stopped').NumberToKeep = 0 #None
$def.RetentionPolicies.Item('PartiallySucceeded').NumberToKeep = 5
$def.RetentionPolicies.Item('Succeeded').NumberToKeep = 5
$def.Save()

您似乎试图使用2008汇编和aprach在tfs 2010上创建构建定义,但没有提供输出或错误。很难判断确切的问题,但很少有什么突出的地方:

  • 使用与您的tfs服务器匹配的程序集版本(正如您标记的问题tfs2010)
  • 对于2010年,建议使用api的方法是从uri创建TfsTeamProjectCollection对象,从那里您可以像现在一样使用get服务
  • 您的代码建议是2008年,2010年tfs构建的工作方式发生了重大变化,特别是DefaultBuildAgent属性已过时且未使用,代理由构建控制器分配,使用以下内容作为脚本的参考

http://geekswithblogs.net/jakob/archive/2010/04/26/creating-a-build-definition-using-the-tfs-2010-api.aspx

最新更新