Skip to content

Fix to stop GitVersion from introducing the remote name into branch name #911

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 3 commits into from
Jun 25, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
public class EnvironmentVariableJenkinsTests
{
string key = "JENKINS_URL";
string branch = "GIT_BRANCH";
string localBranch = "GIT_LOCAL_BRANCH";

private void SetEnvironmentVariableForDetection()
{
Expand All @@ -33,4 +35,29 @@ public void CanNotApplyCurrentContextWhenEnvironmentVariableIsNotSet()
var j = new Jenkins();
j.CanApplyToCurrentContext().ShouldBe(false);
}

[Test]
public void JenkinsTakesLocalBranchNameNotRemoteName()
{
// Save original values so they can be restored
string branchOrig = Environment.GetEnvironmentVariable(branch);
string localBranchOrig = Environment.GetEnvironmentVariable(localBranch);

// Set GIT_BRANCH for testing
Environment.SetEnvironmentVariable(branch, "origin/master");

// Test Jenkins that GetCurrentBranch falls back to GIT_BRANCH if GIT_LOCAL_BRANCH undefined
var j = new Jenkins();
j.GetCurrentBranch(true).ShouldBe("origin/master");

// Set GIT_LOCAL_BRANCH
Environment.SetEnvironmentVariable(localBranch, "master");

// Test Jenkins GetCurrentBranch method now returns GIT_LOCAL_BRANCH
j.GetCurrentBranch(true).ShouldBe("master");

// Restore environment variables
Environment.SetEnvironmentVariable(branch, branchOrig);
Environment.SetEnvironmentVariable(localBranch, localBranchOrig);
}
}
2 changes: 1 addition & 1 deletion src/GitVersionCore/BuildServers/Jenkins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override string[] GenerateSetParameterMessage(string name, string value)

public override string GetCurrentBranch(bool usingDynamicRepos)
{
return Environment.GetEnvironmentVariable("GIT_BRANCH");
return Environment.GetEnvironmentVariable("GIT_LOCAL_BRANCH") ?? Environment.GetEnvironmentVariable("GIT_BRANCH");
}

public override bool PreventFetch()
Expand Down