Skip to content

Commit

Permalink
[FIXED JENKINS-25894] Fix reporting of errors from parallel step.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Apr 12, 2016
1 parent 654e8b4 commit e0ca68f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 50 deletions.
Expand Up @@ -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;
Expand All @@ -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.*;

Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

This file was deleted.

Expand Up @@ -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;
Expand Down Expand Up @@ -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 {",
Expand All @@ -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'",
" }",
"}"
)));
Expand All @@ -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 {",
Expand All @@ -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'",
" }",
"}"
)));
Expand All @@ -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' },",
Expand Down

0 comments on commit e0ca68f

Please sign in to comment.