Skip to content
Permalink
Browse files
Merge pull request #1842 from KostyaSha/patch-3
[FIXED JENKINS-29876] CheckForNull job in ReverseBuildTrigger
  • Loading branch information
oleg-nenashev committed Oct 3, 2015
2 parents 5e2b154 + 45e4e99 commit 339dd4ace545187d04a65bedea44b215fd11ba39
Showing 2 changed files with 37 additions and 2 deletions.
@@ -107,7 +107,7 @@ public Result getThreshold() {

private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
Jenkins jenkins = Jenkins.getInstance();
if (jenkins == null) {
if (jenkins == null || job == null) {
return false;
}
// This checks Item.READ also on parent folders; note we are checking as the upstream auth currently:
@@ -147,7 +147,7 @@ private boolean shouldTrigger(Run upstreamBuild, TaskListener listener) {
}
}

@Override public void start(Job project, boolean newInstance) {
@Override public void start(@Nonnull Job project, boolean newInstance) {
super.start(project, newInstance);
SecurityContext orig = ACL.impersonate(ACL.SYSTEM);
try {
@@ -39,6 +39,8 @@
import hudson.tasks.BuildTrigger;
import hudson.tasks.BuildTriggerTest;
import hudson.triggers.Trigger;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@@ -48,9 +50,16 @@
import jenkins.model.Jenkins;
import jenkins.security.QueueItemAuthenticatorConfiguration;
import org.acegisecurity.Authentication;

import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.core.IsNot.not;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.*;

import org.hamcrest.core.IsNull;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.MockQueueItemAuthenticator;

@@ -148,4 +157,30 @@ public class ReverseBuildTriggerTest {
assertEquals(new Cause.UpstreamCause((Run) b), downstream.getLastBuild().getCause(Cause.UpstreamCause.class));
}

@Issue("JENKINS-29876")
@Test
public void nullJobInTriggerNotCausesNPE() throws Exception {
final FreeStyleProject upstreamJob = r.createFreeStyleProject("upstream");

//job with trigger.job == null
final FreeStyleProject downstreamJob1 = r.createFreeStyleProject("downstream1");
final ReverseBuildTrigger reverseBuildTrigger = new ReverseBuildTrigger("upstream", Result.SUCCESS);
downstreamJob1.addTrigger(reverseBuildTrigger);
downstreamJob1.save();

//job with trigger.job != null
final FreeStyleProject downstreamJob2 = r.createFreeStyleProject("downstream2");
final ReverseBuildTrigger reverseBuildTrigger2 = new ReverseBuildTrigger("upstream", Result.SUCCESS);
downstreamJob2.addTrigger(reverseBuildTrigger2);
downstreamJob2.save();
r.configRoundtrip(downstreamJob2);

r.jenkins.rebuildDependencyGraph();
final FreeStyleBuild build = upstreamJob.scheduleBuild2(0).get();
r.waitUntilNoActivity();

r.assertLogNotContains("java.lang.NullPointerException", build);
assertThat("Build should be not triggered", downstreamJob1.getBuilds(), hasSize(0));
assertThat("Build should be triggered", downstreamJob2.getBuilds(), not(hasSize(0)));
}
}

0 comments on commit 339dd4a

Please sign in to comment.