Skip to content
Permalink
Browse files

[JENKINS-30252] Verifying that ${env.BRANCH_NAME} works.

Also clarifying that BranchJobProperty.branch is nonnull, always.
  • Loading branch information...
jglick committed Nov 2, 2015
1 parent 8555328 commit 7e91ca4f506e596f2abab4c1d45ca076fd30e2c4
@@ -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;
}

@@ -58,9 +58,7 @@
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();
@@ -54,7 +54,7 @@

@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");
@@ -69,8 +69,9 @@
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");
@@ -80,6 +81,7 @@
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

0 comments on commit 7e91ca4

Please sign in to comment.
You can’t perform that action at this time.