Skip to content

MyGet support (output specific to MyGet build server) #289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion GitVersionCore/BuildServers/BuildServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ static IEnumerable<IBuildServer> DefaultSelector(Authentication authentication)
{
new ContinuaCi(authentication),
new TeamCity(authentication),
new AppVeyor(authentication)
new AppVeyor(authentication),
new MyGet(authentication)
};
}

Expand Down
53 changes: 53 additions & 0 deletions GitVersionCore/BuildServers/MyGet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
namespace GitVersion
{
using System;
using System.Collections.Generic;

public class MyGet : BuildServerBase
{
Authentication authentication;

public MyGet(Authentication authentication)
{
this.authentication = authentication;
}

public override bool CanApplyToCurrentContext()
{
var buildRunner = Environment.GetEnvironmentVariable("BuildRunner");

return !string.IsNullOrEmpty(buildRunner)
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
}

public override void PerformPreProcessingSteps(string gitDirectory)
{
if (string.IsNullOrEmpty(gitDirectory))
{
throw new WarningException("Failed to find .git directory on agent.");
}

GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
}

public override string[] GenerateSetParameterMessage(string name, string value)
{
var messages = new List<string>
{
string.Format("##myget[setParameter name='GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value))
};

if (string.Equals(name, "LegacySemVerPadded", StringComparison.InvariantCultureIgnoreCase))
{
messages.Add(string.Format("##myget[buildNumber '{0}']", ServiceMessageEscapeHelper.EscapeValue(value)));
}

return messages.ToArray();
}

public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
{
return null;
}
}
}
24 changes: 3 additions & 21 deletions GitVersionCore/BuildServers/TeamCity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,14 @@ public override string[] GenerateSetParameterMessage(string name, string value)
{
return new[]
{
string.Format("##teamcity[setParameter name='GitVersion.{0}' value='{1}']", name, EscapeValue(value)),
string.Format("##teamcity[setParameter name='system.GitVersion.{0}' value='{1}']", name, EscapeValue(value))
string.Format("##teamcity[setParameter name='GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value)),
string.Format("##teamcity[setParameter name='system.GitVersion.{0}' value='{1}']", name, ServiceMessageEscapeHelper.EscapeValue(value))
};
}

public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
{
return string.Format("##teamcity[buildNumber '{0}']", EscapeValue(versionToUseForBuildNumber));
}

static string EscapeValue(string value)
{
if (value == null)
{
return null;
}
// List of escape values from http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity

value = value.Replace("|", "||");
value = value.Replace("'", "|'");
value = value.Replace("[", "|[");
value = value.Replace("]", "|]");
value = value.Replace("\r", "|r");
value = value.Replace("\n", "|n");

return value;
return string.Format("##teamcity[buildNumber '{0}']", ServiceMessageEscapeHelper.EscapeValue(versionToUseForBuildNumber));
}
}
}
1 change: 1 addition & 0 deletions GitVersionCore/GitVersionCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<Compile Include="BuildServers\ContinuaCi.cs" />
<Compile Include="BuildServers\GitHelper.cs" />
<Compile Include="BuildServers\IBuildServer.cs" />
<Compile Include="BuildServers\MyGet.cs" />
<Compile Include="BuildServers\TeamCity.cs" />
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
Expand Down
20 changes: 20 additions & 0 deletions GitVersionCore/Helpers/DeleteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
{
using System.IO;

public static class ServiceMessageEscapeHelper
{
public static string EscapeValue(string value)
{
if (value == null)
{
return null;
}
// List of escape values from http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity

value = value.Replace("|", "||");
value = value.Replace("'", "|'");
value = value.Replace("[", "|[");
value = value.Replace("]", "|]");
value = value.Replace("\r", "|r");
value = value.Replace("\n", "|n");

return value;
}
}
public static class DeleteHelper
{
public static void DeleteGitRepository(string directory)
Expand Down
33 changes: 33 additions & 0 deletions GitVersionTask.Tests/BuildServers/MyGetTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using GitVersion;
using NUnit.Framework;

[TestFixture]
public class MyGetTests
{
[Test]
public void Develop_branch()
{
var authentication = new Authentication();
var versionBuilder = new MyGet(authentication);
var message = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
Assert.AreEqual(null, message);
}

[Test]
public void EscapeValues()
{
var authentication = new Authentication();
var versionBuilder = new MyGet(authentication);
var message = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
Assert.AreEqual("##myget[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", message[0]);
}

[Test]
public void BuildNumber()
{
var authentication = new Authentication();
var versionBuilder = new MyGet(authentication);
var message = versionBuilder.GenerateSetParameterMessage("LegacySemVerPadded", "0.8.0-unstable568");
Assert.AreEqual("##myget[buildNumber '0.8.0-unstable568']", message[1]);
}
}
1 change: 1 addition & 0 deletions GitVersionTask.Tests/GitVersionTask.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<Compile Include="BranchClassifierTests.cs" />
<Compile Include="BranchFinders\DevelopTests.cs" />
<Compile Include="BuildServers\BuildServerBaseTests.cs" />
<Compile Include="BuildServers\MyGetTests.cs" />
<Compile Include="BuildServers\TeamCityTests.cs" />
<Compile Include="BuildServers\ContinuaCiTests.cs" />
<Compile Include="ConfigReaderTests.cs" />
Expand Down