我们正在从TFS2010迁移到TFS2015 update3。 我们想使用新的TFS2015 XAML控制器和代理名称来更新所有现有的TFS2010 XAML构建定义。有没有一种可以自动完成的方法,因为它需要在所有现有的构建定义上完成。
答案 0 :(得分:0)
您可以尝试使用TFS API更新XAML构建定义:
以下示例供您参考:(有关详细信息,请参考此线程:Updating the build definition for many TFS projects)
像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;
}
}
}