Skip to content

Commit 3cc9f0b

Browse files
committed
Add environment detection, for #313
1 parent be73192 commit 3cc9f0b

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using GitVersion;
3+
using NUnit.Framework;
4+
5+
[TestFixture]
6+
public class EnvironmentVariableJenkinsTests
7+
{
8+
string key = "JENKINS_URL";
9+
10+
private void SetEnvironmentVariableForDetection()
11+
{
12+
Environment.SetEnvironmentVariable(key, "a value", EnvironmentVariableTarget.Process);
13+
}
14+
15+
private void ClearEnvironmentVariableForDetection()
16+
{
17+
Environment.SetEnvironmentVariable(key, null, EnvironmentVariableTarget.Process);
18+
}
19+
20+
[Test, Explicit]
21+
public void CanApplyCurrentContextWhenEnvironmentVariableIsSet()
22+
{
23+
SetEnvironmentVariableForDetection();
24+
var j = new Jenkins();
25+
Assert.True(j.CanApplyToCurrentContext());
26+
}
27+
28+
[Test, Explicit]
29+
public void CanNotApplyCurrentContextWhenEnvironmentVariableIsNotSet()
30+
{
31+
ClearEnvironmentVariableForDetection();
32+
var j = new Jenkins();
33+
Assert.False(j.CanApplyToCurrentContext());
34+
}
35+
36+
}

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
<ItemGroup>
9898
<Compile Include="BuildServers\BuildServerBaseTests.cs" />
9999
<Compile Include="BuildServers\ContinuaCiTests.cs" />
100+
<Compile Include="BuildServers\EnvironmentVariableJenkinsTests.cs" />
100101
<Compile Include="BuildServers\MyGetTests.cs" />
101102
<Compile Include="BuildServers\TeamCityTests.cs" />
102103
<Compile Include="Fixtures\CommitCountingRepoFixture.cs" />

src/GitVersionCore/BuildServers/BuildServerList.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public static class BuildServerList
1010
new ContinuaCi(),
1111
new TeamCity(),
1212
new AppVeyor(),
13-
new MyGet()
13+
new MyGet(),
14+
new Jenkins()
1415
};
1516

1617
public static IEnumerable<IBuildServer> GetApplicableBuildServers()
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace GitVersion
2+
{
3+
using System;
4+
5+
public class Jenkins : BuildServerBase
6+
{
7+
// string _file = "gitversion.properties"
8+
9+
public override bool CanApplyToCurrentContext()
10+
{
11+
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("JENKINS_URL__"));
12+
}
13+
14+
public override string GenerateSetVersionMessage(string versionToUseForBuildNumber)
15+
{
16+
throw new NotImplementedException();
17+
// tbd
18+
}
19+
20+
public override string[] GenerateSetParameterMessage(string name, string value)
21+
{
22+
throw new NotImplementedException();
23+
// this returns an array of property lines
24+
}
25+
26+
public override void WriteIntegration(Action<string> writer, VersionVariables variables)
27+
{
28+
// log message that we're running on jenkins and writing a properties file
29+
// foreach in GenerateSetParameterMessage write line to file
30+
}
31+
}
32+
}

src/GitVersionCore/GitVersionCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
<Compile Include="BuildServers\ContinuaCi.cs" />
7272
<Compile Include="BuildServers\GitHelper.cs" />
7373
<Compile Include="BuildServers\IBuildServer.cs" />
74+
<Compile Include="BuildServers\Jenkins.cs" />
7475
<Compile Include="BuildServers\MyGet.cs" />
7576
<Compile Include="BuildServers\TeamCity.cs" />
7677
<Compile Include="Configuration\BranchConfig.cs" />

0 commit comments

Comments
 (0)