Skip to content
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

add in FOLDER_NAME for the base job of a multibranch project #344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions src/main/java/jenkins/branch/BranchNameContributor.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void buildEnvironmentFor(Job j, EnvVars envs, TaskListener listener) thro
SCMHead head = branch.getHead();
// Note: not using Branch.name, since in the future that could be something different
// than SCMHead.name, which is what we really want here.
envs.put("FOLDER_NAME", parent.getFullName());
envs.put("BRANCH_NAME", head.getName());
if (branch.getAction(PrimaryInstanceMetadataAction.class) != null) {
envs.put("BRANCH_IS_PRIMARY", "true");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ THE SOFTWARE.
<t:buildEnvVar name="TAG_DATE">
<j:out value="${%blurb.TAG_DATE}"/>
</t:buildEnvVar>
<t:buildEnvVar name="FOLDER_NAME">
<j:out value="${%blurb.FOLDER_NAME}"/>
</t:buildEnvVar>
</j:jelly>
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ blurb.TAG_NAME=For a multibranch project corresponding to some kind of tag, this
blurb.TAG_TIMESTAMP=For a multibranch project corresponding to some kind of tag, this will be set to a timestamp of the tag in milliseconds since Unix epoch, if supported; else unset.
blurb.TAG_UNIXTIME=For a multibranch project corresponding to some kind of tag, this will be set to a timestamp of the tag in seconds since Unix epoch, if supported; else unset.
blurb.TAG_DATE=For a multibranch project corresponding to some kind of tag, this will be set to a timestamp in the format as defined by <a href="https://docs.oracle.com/javase/7/docs/api/java/util/Date.html#toString()" target="_blank">java.util.Date#toString()</a> (e.g., Wed Jan 1 00:00:00 UTC 2020), if supported; else unset.
blurb.FOLDER_NAME=For a multibranch project, this will be set to the name of the multibranch project.
1 change: 1 addition & 0 deletions src/test/java/integration/EnvironmentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public void given_multibranch_when_buildingABranch_then_environmentContainsBranc
prj.scheduleBuild2(0).getFuture().get();
r.waitUntilNoActivity();
assertThat(r.getLog(prj.getItem("master").getBuildByNumber(1)), containsString("BRANCH_NAME=master"));
assertThat(r.getLog(prj.getItem("master").getBuildByNumber(1)), containsString("FOLDER_NAME=foo"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,14 @@ public void buildEnvironmentFor() throws Exception {
assertThat("We now have the primary branch", primaryBranch, notNullValue());
EnvVars env = new EnvVars();
instance.buildEnvironmentFor(master, env, new LogTaskListener(LOGGER, Level.FINE));
assertThat(env.keySet(), contains(is("BRANCH_NAME")));
assertThat(env.keySet(), contains(is("BRANCH_NAME"), is("FOLDER_NAME")));
assertThat(env.get("BRANCH_NAME"), is("master"));
assertThat(env.keySet(), not(contains(is("BRANCH_IS_PRIMARY"))));

env = new EnvVars();
instance.buildEnvironmentFor(cr1, env, new LogTaskListener(LOGGER, Level.FINE));
assertThat(env.keySet(), containsInAnyOrder(
is("FOLDER_NAME"),
is("BRANCH_NAME"),
is("CHANGE_ID"),
is("CHANGE_TARGET"),
Expand All @@ -130,6 +131,7 @@ public void buildEnvironmentFor() throws Exception {
env = new EnvVars();
instance.buildEnvironmentFor(cr2, env, new LogTaskListener(LOGGER, Level.FINE));
assertThat(env.keySet(), containsInAnyOrder(
is("FOLDER_NAME"),
is("BRANCH_NAME"),
is("CHANGE_ID"),
is("CHANGE_TARGET"),
Expand All @@ -156,6 +158,7 @@ public void buildEnvironmentFor() throws Exception {
env = new EnvVars();
instance.buildEnvironmentFor(tag, env, new LogTaskListener(LOGGER, Level.FINE));
assertThat(env.keySet(), containsInAnyOrder(
is("FOLDER_NAME"),
is("BRANCH_NAME"),
is("TAG_NAME"),
is("TAG_TIMESTAMP"),
Expand All @@ -172,6 +175,7 @@ public void buildEnvironmentFor() throws Exception {
env = new EnvVars();
instance.buildEnvironmentFor(primaryBranch, env, new LogTaskListener(LOGGER, Level.FINE));
assertThat(env.keySet(), containsInAnyOrder(
is("FOLDER_NAME"),
is("BRANCH_NAME"),
is("BRANCH_IS_PRIMARY")
));
Expand Down