64434

Updating the build definition for many TFS projects

Question:

We're upgrading our TFS farm to TFS 2012. In doing so, we've set up a new build server using the upgrade path in TFS Setup. However our new build controller has the name TFS2012Build, whereas the old one was TFSBuild.

Now I have many hundreds of build definitions that have an invalid build controller. Is there a way to update the build controller automatically or by script?

Answer1:

I am unaware of any "automatic" methodology to do this. It is easy enough to get to the build definitions via the API, and the BuildController is available.

in the absence of decent TFS API documentation, there are many that have examples available for use of the API. A simple google search will reveal these.

A few suggestions to help kick start your effort: <a href="http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.build.client.ibuilddefinition.aspx</a>

A good sample app is here: <a href="http://blogs.microsoft.co.il/blogs/shair/archive/2011/01/11/tfs-api-part-33-get-build-definitions-and-build-details.aspx" rel="nofollow">http://blogs.microsoft.co.il/blogs/shair/archive/2011/01/11/tfs-api-part-33-get-build-definitions-and-build-details.aspx</a>

Finally, there is good code here that edits build definitions, and may be a better starting point for you: <a href="http://geekswithblogs.net/jakob/archive/2009/12/08/tfs-2010-ndash-managing-build-agents-using-the-api.aspx" rel="nofollow">http://geekswithblogs.net/jakob/archive/2009/12/08/tfs-2010-ndash-managing-build-agents-using-the-api.aspx</a>

Good luck.

Answer2:

JamieMeyer had the right idea. There's not much good TFS documentation in MSDN, but there are a lot of good blogger resources. Here's a slightly obfuscated version of the script I created to do this over the course of a very educational weekend. We updated one project's build controllers by hand and then programmatically updated all of the other projects depending on the name of the build. call it like BuildControllerChangeUtil http://tfsserver:8080/tfs/defaultcollection ProjectName where the projectname is a project whose builds have updated build servers.

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; } } }

Recommend

  • Simple example to implement hive based registry?
  • Set DataFormatString on DataGridView at Runtime?
  • how to encode int with base32 in sql server 2008
  • Macos Hadoop 3.1.1 - Failed to start namenode. java.io.IOException: Could not parse line: “Filesyste
  • Using automapper.collection in aspnet core & ef core doesn't updated edited records in a co
  • Store answers in sql table with unique id and store each answer in columns
  • Blue lines in Visual Studio editor margin
  • Why does SelectList SelectedValue work on HttpGet but not on HttpPost?
  • TFS 2017 vNext Build Get workspace with powershell
  • How to mail a log file to yourself using PHP from a Windows machine ?
  • Modifying resource contents of a running executable
  • Publishing test results through command line test runner in VSTS
  • TFS Builds: Running the builds as administrator
  • TFS edit build log using custom activity
  • displaying markdown in my textarea
  • SSRS 2008 - Sorting within a group
  • c++ search a vector for element first seen position
  • Programatically open file in visual studio
  • Is there any purpose for h2-h6 headings in HTML5?
  • Where these are stored?
  • iOS: Detect app start via notification press
  • How to attach a node.js readable stream to a Sendgrid email?
  • formatting the colorbar ticklabels with SymLogNorm normalization in matplotlib
  • Android screen density dpi vs ppi
  • Master page gives error
  • What is Eclipse's Declaration View used for?
  • How would I use PHP exceptions to define a redirect?
  • How to extract text from Word files using C#?
  • Hazelcast - OperationTimeoutException
  • Jquery - Jquery Wysiwyg return html as a string
  • SVN: Merging two branches together
  • RestKit - RKRequestDelegate does not exist
  • Matrix multiplication with MKL
  • Revoking OAuth Access Token Results in 404 Not Found
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • need help with bizarre java.net.HttpURLConnection behavior
  • How can I remove ASP.NET Designer.cs files?
  • Append folder name and increment by 1 using batch script
  • java string with new operator and a literal