简体   繁体   English

用于构建 TFS 定义的 PowerShell 脚本

[英]PowerShell Script to Build TFS Definition

I am trying to create a PS script to create TFS build definition files.我正在尝试创建一个 PS 脚本来创建 TFS 构建定义文件。 I found below example.我发现下面的例子。 But, it's not working properly.但是,它不能正常工作。 I tried to follow the example and create a script without any success.我试图按照示例创建一个脚本,但没有成功。 Any help in identifying why below script is not working is appreciated and also guidance on how to create a PS script or an example感谢您对确定以下脚本为何不起作用的任何帮助以及有关如何创建 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()

You seem to try to create build definition on tfs 2010 using 2008 assembly and aproach, without provided outputs or errors is hard to tell exact issue, but few thing stand out:您似乎尝试使用 2008 程序集和方法在 tfs 2010 上创建构建定义,没有提供的输出或错误很难说出确切的问题,但很少有突出的地方:

  • use the version of assemblies that match your tfs server (as you tagged question tfs2010)使用与您的 tfs 服务器匹配的程序集版本(因为您标记了问题 tfs2010)
  • For 2010 suggested way have to work with api is to create TfsTeamProjectCollection object from uri, from there you will use get service as you do now.对于 2010 年,必须使用 api 的建议方法是从 uri 创建 TfsTeamProjectCollection 对象,从那里您将像现在一样使用 get 服务。
  • Your code suggest is for 2008, there have been major changes how tfs builds work in 2010, specificly DefaultBuildAgent property is obsolete and unused, agents are assigned by build controller use following as reference for your script.您的代码建议是针对 2008 年的,2010 年 tfs 构建的工作方式发生了重大变化,特别是 DefaultBuildAgent 属性已过时且未使用,代理由构建控制器分配使用,以下作为您脚本的参考。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM