我正在尝试创建一个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 = "\\build\PrivateDrops"
$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()
答案 0 :(得分:0)
您似乎尝试使用2008程序集和aproach在tfs 2010上创建构建定义,没有提供输出或错误很难说出确切的问题,但很少有事情突出: