Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
TC config updater for building project branches
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace Move.Platform.TeamCityBranchUpdaterTool
{
public static class Program
{
public static void Main(string[] args)
{
var lsRemote = File.ReadAllLines("ls-remote.txt");
const string projectConfigXml = "project-config.xml";
var projectConfig = File.ReadAllText(projectConfigXml);
var rxRef = new Regex("refs/heads/(.*)$");
var branches = new HashSet<string>(from line in lsRemote select rxRef.Match(line) into match where match.Success select match.Groups[1].Value);
var rxBuild = new Regex(@"<build-type\s+id=""([^""]+)"".*?</build-type>", RegexOptions.Singleline);
projectConfig = rxBuild.Replace(projectConfig,m =>{var name = m.Groups[1].Value;if (branches.Contains(name)){branches.Remove(name);return m.Value;}return string.Empty;});
var newBranches = string.Join(Environment.NewLine,branches.Select(b =>"<build-type id=\"" + b + "\" name=\"" + b +"\"><settings ref=\"template\"></settings></build-type>"));
projectConfig = projectConfig.Replace("</project>", newBranches + "</project>");
File.WriteAllText(projectConfigXml, projectConfig);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.