Skip to content

Commit

Permalink
[JENKINS-30252] Verifying that ${env.BRANCH_NAME} works.
Browse files Browse the repository at this point in the history
Also clarifying that BranchJobProperty.branch is nonnull, always.

Originally-Committed-As: 7e91ca4f506e596f2abab4c1d45ca076fd30e2c4
  • Loading branch information
jglick committed Nov 2, 2015
1 parent f19ab8f commit 05869c1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Expand Up @@ -39,9 +39,13 @@
*/
public class BranchJobProperty extends WorkflowJobProperty {

private /*@Nonnull once initialized */ Branch branch;
private @Nonnull Branch branch;

public synchronized Branch getBranch() {
BranchJobProperty(@Nonnull Branch branch) {
this.branch = branch;
}

public synchronized @Nonnull Branch getBranch() {
return branch;
}

Expand Down
Expand Up @@ -58,9 +58,7 @@ public class WorkflowBranchProjectFactory extends BranchProjectFactory<WorkflowJ
BranchJobProperty property = project.getProperty(BranchJobProperty.class);
try {
if (property == null) {
property = new BranchJobProperty();
property.setBranch(branch);
project.addProperty(property);
project.addProperty(new BranchJobProperty(branch));
} else if (!property.getBranch().equals(branch)) {
property.setBranch(branch);
project.save();
Expand Down
Expand Up @@ -54,7 +54,7 @@ public class WorkflowMultiBranchProjectTest {

@Test public void basicBranches() throws Exception {
sampleRepo.init();
sampleRepo.write("Jenkinsfile", "node {checkout scm; echo readFile('file')}");
sampleRepo.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; node {checkout scm; echo readFile('file')}");
sampleRepo.write("file", "initial content");
sampleRepo.git("add", "Jenkinsfile");
sampleRepo.git("commit", "--all", "--message=flow");
Expand All @@ -69,8 +69,9 @@ public class WorkflowMultiBranchProjectTest {
WorkflowRun b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
r.assertLogContains("initial content", b1);
r.assertLogContains("branch=master", b1);
sampleRepo.git("checkout", "-b", "feature");
sampleRepo.write("Jenkinsfile", "node {checkout scm; echo readFile('file').toUpperCase()}");
sampleRepo.write("Jenkinsfile", "echo \"branch=${env.BRANCH_NAME}\"; node {checkout scm; echo readFile('file').toUpperCase()}");
ScriptApproval.get().approveSignature("method java.lang.String toUpperCase");
sampleRepo.write("file", "subsequent content");
sampleRepo.git("commit", "--all", "--message=tweaked");
Expand All @@ -80,6 +81,7 @@ public class WorkflowMultiBranchProjectTest {
b1 = p.getLastBuild();
assertEquals(1, b1.getNumber());
r.assertLogContains("SUBSEQUENT CONTENT", b1);
r.assertLogContains("branch=feature", b1);
}

// TODO commit notifications can both add branch projects and build them
Expand Down

0 comments on commit 05869c1

Please sign in to comment.