Skip to content

Commit 1efa2b7

Browse files
BehrhorstBehrhorst
Behrhorst
authored and
Behrhorst
committed
added fallback to GIT_BRANCH in case GIT_LOCAL_BRANCH is not defined
1 parent 79c765c commit 1efa2b7

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/GitVersionCore.Tests/BuildServers/EnvironmentVariableJenkinsTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ public void JenkinsTakesLocalBranchNameNotRemoteName()
4343
string branchOrig = Environment.GetEnvironmentVariable(branch);
4444
string localBranchOrig = Environment.GetEnvironmentVariable(localBranch);
4545

46-
// Set new Environment variables for testing
46+
// Set GIT_BRANCH for testing
4747
Environment.SetEnvironmentVariable(branch, "origin/master");
48-
Environment.SetEnvironmentVariable(localBranch, "master");
4948

50-
// Test Jenkins GetCurrentBranch method
49+
// Test Jenkins that GetCurrentBranch falls back to GIT_BRANCH if GIT_LOCAL_BRANCH undefined
5150
var j = new Jenkins();
51+
j.GetCurrentBranch(true).ShouldBe("origin/master");
52+
53+
// Set GIT_LOCAL_BRANCH
54+
Environment.SetEnvironmentVariable(localBranch, "master");
55+
56+
// Test Jenkins GetCurrentBranch method now returns GIT_LOCAL_BRANCH
5257
j.GetCurrentBranch(true).ShouldBe("master");
5358

5459
// Restore environment variables

src/GitVersionCore/BuildServers/Jenkins.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)
3636

3737
public override string GetCurrentBranch(bool usingDynamicRepos)
3838
{
39-
return Environment.GetEnvironmentVariable("GIT_LOCAL_BRANCH");
39+
return Environment.GetEnvironmentVariable("GIT_LOCAL_BRANCH") ?? Environment.GetEnvironmentVariable("GIT_BRANCH");
4040
}
4141

4242
public override bool PreventFetch()

0 commit comments

Comments
 (0)