Skip to content

Commit 2f67087

Browse files
Extract build server environment variable names to constants
1 parent 289c543 commit 2f67087

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

src/GitVersionCore.Tests/ExecuteCoreTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public void DynamicRepositoriesShouldNotErrorWithFailedToFindGitDirectory()
141141
string RepositoryScope(ExecuteCore executeCore = null, Action<EmptyRepositoryFixture, VersionVariables> fixtureAction = null)
142142
{
143143
// Make sure GitVersion doesn't trigger build server mode when we are running the tests
144-
Environment.SetEnvironmentVariable("APPVEYOR", null);
145-
Environment.SetEnvironmentVariable("TRAVIS", null);
144+
Environment.SetEnvironmentVariable(AppVeyor.EnvironmentVariableName, null);
145+
Environment.SetEnvironmentVariable(TravisCI.EnvironmentVariableName, null);
146146
var infoBuilder = new StringBuilder();
147147
Action<string> infoLogger = s =>
148148
{

src/GitVersionCore/BuildServers/AppVeyor.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66

77
public class AppVeyor : BuildServerBase
88
{
9-
public override bool CanApplyToCurrentContext()
9+
public const string EnvironmentVariableName = "APPVEYOR";
10+
11+
public override bool CanApplyToCurrentContext()
1012
{
11-
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPVEYOR"));
13+
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(EnvironmentVariableName));
1214
}
1315

1416
public override string GenerateSetVersionMessage(VersionVariables variables)

src/GitVersionCore/BuildServers/TeamCity.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
public class TeamCity : BuildServerBase
66
{
7-
public override bool CanApplyToCurrentContext()
7+
public const string EnvironmentVariableName = "TEAMCITY_VERSION";
8+
9+
public override bool CanApplyToCurrentContext()
810
{
9-
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("TEAMCITY_VERSION"));
11+
return !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(EnvironmentVariableName));
1012
}
1113

1214
public override string GetCurrentBranch(bool usingDynamicRepos)

src/GitVersionCore/BuildServers/TravisCI.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ namespace GitVersion
33
{
44
public class TravisCI : BuildServerBase
55
{
6+
public const string EnvironmentVariableName = "TRAVIS";
7+
68
public override bool CanApplyToCurrentContext ()
79
{
8-
return "true".Equals(Environment.GetEnvironmentVariable ("TRAVIS")) && "true".Equals(Environment.GetEnvironmentVariable("CI"));
10+
return "true".Equals(Environment.GetEnvironmentVariable(EnvironmentVariableName)) && "true".Equals(Environment.GetEnvironmentVariable("CI"));
911
}
1012

1113
public override string GenerateSetVersionMessage(VersionVariables variables)

src/GitVersionExe.Tests/GitVersionHelper.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using System.Text;
55
using GitTools;
6+
using GitVersion;
67

78
public static class GitVersionHelper
89
{
@@ -36,9 +37,9 @@ static ExecutionResults ExecuteIn(ArgumentBuilder arguments)
3637
var environmentalVariables =
3738
new[]
3839
{
39-
new KeyValuePair<string, string>("TEAMCITY_VERSION", arguments.IsTeamCity ? "8.0.0" : null),
40-
new KeyValuePair<string, string>("APPVEYOR", null),
41-
new KeyValuePair<string, string>("TRAVIS", null),
40+
new KeyValuePair<string, string>(TeamCity.EnvironmentVariableName, arguments.IsTeamCity ? "8.0.0" : null),
41+
new KeyValuePair<string, string>(AppVeyor.EnvironmentVariableName, null),
42+
new KeyValuePair<string, string>(TravisCI.EnvironmentVariableName, null),
4243
};
4344

4445
var exitCode = -1;

0 commit comments

Comments
 (0)