Skip to content
Permalink
Browse files

Merge pull request #16 from jglick/BuildTriggerListener.onDeleted-JEN…

…KINS-46934

[JENKINS-46934] StepContext.onFailure could block; we should not block listeners on it
  • Loading branch information...
svanoort committed Oct 5, 2017
2 parents 3dfefde + 02e1925 commit 269bccee26540da208440de574e3f6d62b7e31dc
@@ -8,11 +8,10 @@
import hudson.model.TaskListener;
import hudson.model.listeners.RunListener;
import java.util.logging.Level;
import org.jenkinsci.plugins.workflow.steps.StepContext;

import java.util.logging.Logger;
import static java.util.logging.Level.WARNING;
import javax.annotation.Nonnull;
import jenkins.util.Timer;
import org.jenkinsci.plugins.workflow.steps.StepContext;

@Extension
public class BuildTriggerListener extends RunListener<Run<?,?>>{
@@ -30,7 +29,7 @@ public void onStarted(Run<?, ?> run, TaskListener listener) {
// encodeTo(Run) calls getDisplayName, which does not include the project name.
taskListener.getLogger().println("Starting building: " + ModelHyperlinkNote.encodeTo("/" + run.getUrl(), run.getFullDisplayName()));
} catch (Exception e) {
LOGGER.log(WARNING, null, e);
LOGGER.log(Level.WARNING, null, e);
}
} else {
LOGGER.log(Level.FINE, "{0} unavailable in {1}", new Object[] {stepContext, run});
@@ -57,9 +56,13 @@ public void onCompleted(Run<?,?> run, @Nonnull TaskListener listener) {
}

@Override
public void onDeleted(Run<?,?> run) {
for (BuildTriggerAction.Trigger trigger : BuildTriggerAction.triggersFor(run)) {
trigger.context.onFailure(new AbortException(run.getFullDisplayName() + " was deleted"));
public void onDeleted(final Run<?,?> run) {
for (final BuildTriggerAction.Trigger trigger : BuildTriggerAction.triggersFor(run)) {
Timer.get().submit(new Runnable() {
@Override public void run() {
trigger.context.onFailure(new AbortException(run.getFullDisplayName() + " was deleted"));
}
});
}
}
}
@@ -19,7 +19,6 @@
import hudson.model.TaskListener;
import hudson.model.User;
import hudson.model.queue.QueueTaskFuture;
import hudson.security.AuthorizationStrategy;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@@ -317,16 +316,16 @@ public void cancelBuildQueue() throws Exception {
@Issue("JENKINS-28063")
@Test public void coalescedQueue() throws Exception {
FreeStyleProject ds = j.createFreeStyleProject("ds");
ds.setQuietPeriod(3);
ds.setConcurrentBuild(true);
ds.getBuildersList().add(new SleepBuilder(3000));
WorkflowJob us = j.jenkins.createProject(WorkflowJob.class, "us");
us.setDefinition(new CpsFlowDefinition("echo \"triggered #${build('ds').number}\"", true));
QueueTaskFuture<WorkflowRun> us1F = us.scheduleBuild2(0);
us1F.waitForStart(); // make sure we do not coalesce the us `Queue.Item`s
QueueTaskFuture<WorkflowRun> us2F = us.scheduleBuild2(0);
WorkflowRun us1 = us1F.get();
WorkflowRun us1 = us.scheduleBuild2(0).waitForStart();
assertEquals(1, us1.getNumber());
j.assertLogContains("triggered #1", us1);
j.waitForMessage("Scheduling project: ds", us1);
QueueTaskFuture<WorkflowRun> us2F = us.scheduleBuild2(0);
j.assertLogContains("triggered #1", j.waitForCompletion(us1));
WorkflowRun us2 = us2F.get();
assertEquals(2, us2.getNumber());
j.assertLogContains("triggered #1", us2);

0 comments on commit 269bcce

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