Skip to content

Commit

Permalink
[JENKINS-46934] StepContext.onFailure could block; we should not bloc…
Browse files Browse the repository at this point in the history
…k listeners on it.
  • Loading branch information
jglick committed Sep 18, 2017
1 parent 3dfefde commit 696921e
Showing 1 changed file with 10 additions and 7 deletions.
Expand Up @@ -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<?,?>>{
Expand All @@ -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});
Expand All @@ -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"));
}
});
}
}
}

0 comments on commit 696921e

Please sign in to comment.