Skip to content
Permalink
Browse files

[FIXED JENKINS-25894] Fix reporting of errors from parallel step.

  • Loading branch information...
jglick committed Apr 12, 2016
1 parent 654e8b4 commit e0ca68f17d3eeeb52ca0db73ff1bf10e2558bfe6
@@ -5,6 +5,7 @@
import groovy.lang.Closure;
import hudson.Extension;
import hudson.model.TaskListener;
import java.io.IOException;

import org.jenkinsci.plugins.workflow.cps.CpsVmThreadOnly;
import org.jenkinsci.plugins.workflow.cps.persistence.PersistIn;
@@ -23,6 +24,8 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.jenkinsci.plugins.workflow.cps.persistence.PersistenceContext.*;

@@ -35,6 +38,8 @@
*/
public class ParallelStep extends Step {

private static final Logger LOGGER = Logger.getLogger(ParallelStep.class.getName());

/** should a failure in a parallel branch terminate other still executing branches. */
private final boolean failFast;

@@ -113,8 +118,15 @@ public void onSuccess(StepContext context, Object result) {
@Override
public void onFailure(StepContext context, Throwable t) {
handler.outcomes.put(name, new Outcome(null, t));
try {
context.get(TaskListener.class).getLogger().println("Failed in branch " + name);
} catch (IOException | InterruptedException x) {
LOGGER.log(Level.WARNING, null, x);
}
if (handler.originalFailure == null) {
handler.originalFailure = new SimpleEntry<String, Throwable>(name, t);
} else {
handler.originalFailure.getValue().addSuppressed(t);
}
checkAllDone(true);
}
@@ -149,8 +161,7 @@ private void checkAllDone(boolean stepFailed) {
}
// all done
if (handler.originalFailure!=null) {
// wrap the exception so that the call stack leading up to parallel is visible
handler.context.onFailure(new ParallelStepException(handler.originalFailure.getKey(), handler.originalFailure.getValue()));
handler.context.onFailure(handler.originalFailure.getValue());
} else {
handler.context.onSuccess(success);
}

This file was deleted.

@@ -11,8 +11,6 @@
import org.jenkinsci.plugins.workflow.SingleJobTestBase;
import org.jenkinsci.plugins.workflow.actions.ThreadNameAction;
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition;
import org.jenkinsci.plugins.workflow.cps.steps.ParallelStep;
import org.jenkinsci.plugins.workflow.cps.steps.ParallelStepException;
import org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.steps.EchoStep;
@@ -72,7 +70,6 @@ public void failure_in_subflow_will_cause_join_to_fail() throws Exception {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"import "+AbortException.class.getName(),
"import "+ParallelStepException.class.getName(),

"node {",
" try {",
@@ -83,9 +80,8 @@ public void failure_in_subflow_will_cause_join_to_fail() throws Exception {
" a: { sleep 3; writeFile text: '', file: 'a.done' }",
" )",
" assert false;",
" } catch (ParallelStepException e) {",
" assert e.name=='b'",
" assert e.cause instanceof AbortException",
" } catch (AbortException e) {",
" assert e.message == 'died'",
" }",
"}"
)));
@@ -111,7 +107,6 @@ public void failure_in_subflow_will_fail_fast() throws Exception {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"import "+AbortException.class.getName(),
"import "+ParallelStepException.class.getName(),

"node {",
" try {",
@@ -123,10 +118,8 @@ public void failure_in_subflow_will_fail_fast() throws Exception {
" failFast: true",
" )",
" assert false",
" } catch (ParallelStepException e) {",
" echo e.toString()",
" assert e.name=='b'",
" assert e.cause instanceof AbortException",
" } catch (AbortException e) {",
" assert e.message == 'died'",
" }",
"}"
)));
@@ -148,9 +141,6 @@ public void failFast_has_no_effect_on_success() throws Exception {
@Override public void evaluate() throws Throwable {
p = jenkins().createProject(WorkflowJob.class, "demo");
p.setDefinition(new CpsFlowDefinition(join(
"import "+AbortException.class.getName(),
"import "+ParallelStepException.class.getName(),

"node {",
" parallel(",
" a: { echo 'hello from a';sleep 1;echo 'goodbye from a' },",

0 comments on commit e0ca68f

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