Skip to content

Instantly share code, notes, and snippets.

@rfennell
Last active December 20, 2016 16:41
Show Gist options
  • Save rfennell/01ca5d09f87a02d980b7fac1054da546 to your computer and use it in GitHub Desktop.
Save rfennell/01ca5d09f87a02d980b7fac1054da546 to your computer and use it in GitHub Desktop.
Transform tool for transferring TFS 2015.3 Release Templates to VSTS
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
namespace RMTransform
{
class Program
{
static void Main(string[] args)
{
if ((args.Count() != 3) ||
(File.Exists(args[0]) == false) ||
(File.Exists(args[1]) == false) )
{
Console.WriteLine("Usage: RMTransform template.json source.json output.json");
}
else
{
RMTransForm(args[0], args[1], args[2]);
Console.WriteLine("Exported the transformed file");
}
}
private static void RMTransForm(string templateFile, string sourceFile, string outputFile)
{
var template = JObject.Parse(File.ReadAllText(templateFile));
var source = JObject.Parse(File.ReadAllText(sourceFile));
//Does not handle agent queue
//Does not handle approvals, accounts
template["name"] = source["name"];
template["releaseNameFormat"] = source["releaseNameFormat"];
template["variables"] = source["variables"]; // only appears after save
template["artifacts"] = source["artifacts"]; // only appears after save
template["triggers"] = source["triggers"]; // only appears after save
for (var i = 0; i < ((JArray)source["environments"]).Count; i++)
{
if (i == ((JArray)template["environments"]).Count)
{
((JArray)template["environments"]).Add(template["environments"][i - 1]); // use the first one as a template
}
template["environments"][i]["name"] = source["environments"][i]["name"];
template["environments"][i]["rank"] = source["environments"][i]["rank"];
template["environments"][i]["variables"] = source["environments"][i]["variables"];
template["environments"][i]["demands"] = source["environments"][i]["demands"];
template["environments"][i]["conditions"] = source["environments"][i]["conditions"];
template["environments"][i]["preDeployApprovals"] = source["environments"][i]["preDeployApprovals"];
template["environments"][i]["postDeployApprovals"] = source["environments"][i]["postDeployApprovals"];
template["environments"][i]["deployPhases"][0]["workflowTasks"] = source["environments"][i]["deployStep"]["tasks"];
}
File.WriteAllText(outputFile, template.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment