我们正在将TFS服务器场升级到TFS 2012.在此过程中,我们使用TFS安装程序中的升级路径设置了新的构建服务器。但是我们的新构建控制器名称为TFS2012Build,而旧构建控制器的名称为TFSBuild。
现在我有数百个具有无效构建控制器的构建定义。有没有办法自动或通过脚本更新构建控制器?
答案 0 :(得分:2)
我不知道有任何“自动”方法可以做到这一点。通过API获取构建定义很容易,BuildController也可用。
在没有合适的TFS API文档的情况下,有很多可以使用API的示例。一个简单的谷歌搜索将揭示这些。
一些建议可以帮助你开始努力: http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx
最后,这里有很好的代码可以编辑构建定义,对您来说可能是一个更好的起点:http://geekswithblogs.net/jakob/archive/2009/12/08/tfs-2010-ndash-managing-build-agents-using-the-api.aspx
祝你好运。答案 1 :(得分:0)
JamieMeyer有正确的想法。在MSDN中没有太多好的TFS文档,但是有很多很好的博客资源。这是我在一个非常有教育意义的周末期间创建的脚本的略微模糊版本。我们手动更新了一个项目的构建控制器,然后根据构建的名称以编程方式更新所有其他项目。称之为BuildControllerChangeUtil http://tfsserver:8080/tfs/defaultcollection ProjectName
,其中projectname是一个项目,其构建已更新构建服务器。
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using System;
using System.Collections.Generic;
using System.Linq;
namespace BuildControllerChangeUtil
{
class Program
{
static void Main(string[] args)
{
string tfsDefaultcollection = args[0];
string knownGoodProject = args[1];
var tfs = new TfsTeamProjectCollection(new Uri(tfsDefaultcollection));
var buildServer = tfs.GetService<IBuildServer>();
var knownGoodDefs = buildServer.QueryBuildDefinitions(knownGoodProject);
var testController = knownGoodDefs.First(bd => bd.Name.Equals("Test")).BuildController ;
var releaseController = knownGoodDefs.First(bd => bd.Name.Equals("Release")).BuildController ;
foreach (var teamProject in GetTfsProjects( tfsDefaultcollection ))
{
var buildDetails = buildServer.QueryBuildDefinitions(teamProject);
if (!buildDetails.Any())
{
Console.WriteLine("{0} has no build defintions. ", teamProject);
}
foreach (var thisBuild in buildDetails)
{
if (thisBuild.Name.ToUpperInvariant().Contains("TEST"))
{
SetBuildController(teamProject, thisBuild, testController);
}
else if (thisBuild.Name.ToUpperInvariant().Contains("PRODUCTION"))
{
SetBuildController(teamProject, thisBuild, releaseController);
}
else
{
Console.Error.WriteLine( "Team project {0} had an unknown build name {1}",teamProject , thisBuild.Name);
}
}
}
}
private static void SetBuildController(string teamProject, IBuildDefinition thisBuild, IBuildController bc)
{
Console.WriteLine("setting {0} build {1} build controller to {2}", teamProject , thisBuild.Name, bc.Name );
thisBuild.BuildController = bc;
thisBuild.Save();
}
private static IEnumerable<string> GetTfsProjects(string tfsAddress)
{
var tpcAddress = new Uri(tfsAddress);
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcAddress);
tpc.Authenticate();
var workItemStore = new WorkItemStore(tpc);
var projectList = (from Project pr in workItemStore.Projects select pr.Name).ToList();
return projectList;
}
}
}