Skip to content

Commit

Permalink
[FIXED JENKINS-44676] Add TAG_NAME when head is of type tag.
Browse files Browse the repository at this point in the history
Closes #100
  • Loading branch information
Niklas Tanskanen authored and stephenc committed Jun 15, 2017
1 parent 1610811 commit a174897
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/jenkins/branch/BranchNameContributor.java
Expand Up @@ -31,11 +31,12 @@
import hudson.model.Job;
import hudson.model.TaskListener;
import java.io.IOException;
import jenkins.scm.api.mixin.ChangeRequestSCMHead;
import jenkins.scm.api.SCMHead;
import jenkins.scm.api.actions.ChangeRequestAction;
import jenkins.scm.api.metadata.ContributorMetadataAction;
import jenkins.scm.api.metadata.ObjectMetadataAction;
import jenkins.scm.api.mixin.ChangeRequestSCMHead;
import jenkins.scm.api.mixin.TagSCMHead;

/**
* Defines the environment variable {@code BRANCH_NAME} for multibranch builds.
Expand Down Expand Up @@ -73,6 +74,9 @@ public void buildEnvironmentFor(Job j, EnvVars envs, TaskListener listener) thro
envs.putIfNotNull("CHANGE_AUTHOR_EMAIL", cma.getContributorEmail());
}
}
if (head instanceof TagSCMHead) {
envs.put("TAG_NAME", head.getName());
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/test/java/integration/EnvironmentTest.java
Expand Up @@ -129,4 +129,21 @@ public void given_multibranch_when_buildingAChangeRequest_then_environmentContai
}
}

public void given_multibranch_when_buildingATag_then_environmentContainsTagName() throws Exception {
try (MockSCMController c = MockSCMController.create()) {
c.createRepository("foo");
c.createTag("foo", "master", "release");
BasicMultiBranchProject prj = r.jenkins.createProject(BasicMultiBranchProject.class, "foo");
prj.setCriteria(null);
prj.setProjectFactory(new BasicBranchProjectFactory());
BranchSource source = new BranchSource(new MockSCMSource(null, c, "foo", true, true, false));
source.setStrategy(
new DefaultBranchPropertyStrategy(new BranchProperty[]{new BasicDummyStepBranchProperty()}));
prj.getSourcesList().add(source);
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(r.getLog(prj.getItem("release").getBuildByNumber(1)), containsString("TAG_NAME=release"));
}
}

}

0 comments on commit a174897

Please sign in to comment.