Skip to content

Commit 7be161f

Browse files
committed
Added MyGet Build Services support
1 parent 9ca5b6c commit 7be161f

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed

GitVersionCore/BuildServers/BuildServerList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static IEnumerable<IBuildServer> DefaultSelector(Authentication authentication)
2727
{
2828
new ContinuaCi(authentication),
2929
new TeamCity(authentication),
30-
new AppVeyor(authentication)
30+
new AppVeyor(authentication),
31+
new MyGet(authentication)
3132
};
3233
}
3334

GitVersionCore/BuildServers/MyGet.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
public class MyGet : BuildServerBase
6+
{
7+
Authentication authentication;
8+
9+
public MyGet(Authentication authentication)
10+
{
11+
this.authentication = authentication;
12+
}
13+
14+
public override bool CanApplyToCurrentContext()
15+
{
16+
var buildRunner = Environment.GetEnvironmentVariable("BuildRunner");
17+
18+
return !string.IsNullOrEmpty(buildRunner)
19+
&& buildRunner.Equals("MyGet", StringComparison.InvariantCultureIgnoreCase);
20+
}
21+
22+
public override void PerformPreProcessingSteps(string gitDirectory)
23+
{
24+
if (string.IsNullOrEmpty(gitDirectory))
25+
{
26+
throw new WarningException("Failed to find .git directory on agent.");
27+
}
28+
29+
GitHelper.NormalizeGitDirectory(gitDirectory, authentication);
30+
}
31+
32+
public override string[] GenerateSetParameterMessage(string name, string value)
33+
{
34+
return new[]
35+
{
36+
string.Format("##teamcity[setParameter name='GitVersion.{0}' value='{1}']", name, EscapeValue(value)),
37+
string.Format("##teamcity[setParameter name='system.GitVersion.{0}' value='{1}']", name, EscapeValue(value))
38+
};
39+
}
40+
41+
public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
42+
{
43+
return string.Format("##teamcity[buildNumber '{0}']", EscapeValue(versionToUseForBuildNumber));
44+
}
45+
46+
static string EscapeValue(string value)
47+
{
48+
if (value == null)
49+
{
50+
return null;
51+
}
52+
// List of escape values from http://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity
53+
54+
value = value.Replace("|", "||");
55+
value = value.Replace("'", "|'");
56+
value = value.Replace("[", "|[");
57+
value = value.Replace("]", "|]");
58+
value = value.Replace("\r", "|r");
59+
value = value.Replace("\n", "|n");
60+
61+
return value;
62+
}
63+
}
64+
}

GitVersionCore/GitVersionCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
<Compile Include="BuildServers\ContinuaCi.cs" />
6363
<Compile Include="BuildServers\GitHelper.cs" />
6464
<Compile Include="BuildServers\IBuildServer.cs" />
65+
<Compile Include="BuildServers\MyGet.cs" />
6566
<Compile Include="BuildServers\TeamCity.cs" />
6667
<Compile Include="GitFlow\BranchFinders\BranchCommitDifferenceFinder.cs" />
6768
<Compile Include="GitFlow\BranchFinders\RecentTagVersionExtractor.cs" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using GitVersion;
2+
using NUnit.Framework;
3+
4+
[TestFixture]
5+
public class MyGetTests
6+
{
7+
[Test]
8+
public void Develop_branch()
9+
{
10+
var authentication = new Authentication();
11+
var versionBuilder = new MyGet(authentication);
12+
var message = versionBuilder.GenerateSetVersionMessage("0.0.0-Unstable4");
13+
Assert.AreEqual("##teamcity[buildNumber '0.0.0-Unstable4']", message);
14+
}
15+
16+
[Test]
17+
public void EscapeValues()
18+
{
19+
var authentication = new Authentication();
20+
var versionBuilder = new MyGet(authentication);
21+
var message = versionBuilder.GenerateSetParameterMessage("Foo", "0.8.0-unstable568 Branch:'develop' Sha:'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb'");
22+
Assert.AreEqual("##teamcity[setParameter name='GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", message[0]);
23+
Assert.AreEqual("##teamcity[setParameter name='system.GitVersion.Foo' value='0.8.0-unstable568 Branch:|'develop|' Sha:|'ee69bff1087ebc95c6b43aa2124bd58f5722e0cb|'']", message[1]);
24+
}
25+
26+
}

GitVersionTask.Tests/GitVersionTask.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
<Compile Include="BranchClassifierTests.cs" />
9090
<Compile Include="BranchFinders\DevelopTests.cs" />
9191
<Compile Include="BuildServers\BuildServerBaseTests.cs" />
92+
<Compile Include="BuildServers\MyGetTests.cs" />
9293
<Compile Include="BuildServers\TeamCityTests.cs" />
9394
<Compile Include="BuildServers\ContinuaCiTests.cs" />
9495
<Compile Include="ConfigReaderTests.cs" />

0 commit comments

Comments
 (0)