diff --git a/core/src/main/java/hudson/model/AbstractBuild.java b/core/src/main/java/hudson/model/AbstractBuild.java index e4fe7a2990..856fb07c00 100644 --- a/core/src/main/java/hudson/model/AbstractBuild.java +++ b/core/src/main/java/hudson/model/AbstractBuild.java @@ -546,8 +546,8 @@ public abstract class AbstractBuild
,R extends Abs // default is no-op } - protected final void performAllBuildStep(BuildListener listener, Map,? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException { - performAllBuildStep(listener,buildSteps.values(),phase); + protected final boolean performAllBuildStep(BuildListener listener, Map,? extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException { + return performAllBuildStep(listener,buildSteps.values(),phase); } /** @@ -556,17 +556,19 @@ public abstract class AbstractBuild
,R extends Abs * @param phase * true for the post build processing, and false for the final "run after finished" execution. */ - protected final void performAllBuildStep(BuildListener listener, Iterable extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException { + protected final boolean performAllBuildStep(BuildListener listener, Iterable extends BuildStep> buildSteps, boolean phase) throws InterruptedException, IOException { + boolean r = true; for (BuildStep bs : buildSteps) { if ((bs instanceof Publisher && ((Publisher)bs).needsToRunAfterFinalized()) ^ phase) try { - perform(bs,listener); + r &= perform(bs,listener); } catch (Exception e) { String msg = "Publisher " + bs.getClass().getName() + " aborted due to exception"; e.printStackTrace(listener.error(msg)); LOGGER.log(Level.WARNING, msg, e); } } + return r; } /** diff --git a/core/src/main/java/hudson/model/Build.java b/core/src/main/java/hudson/model/Build.java index 62139b5a13..9b21c9674a 100644 --- a/core/src/main/java/hudson/model/Build.java +++ b/core/src/main/java/hudson/model/Build.java @@ -38,6 +38,8 @@ import java.util.Collection; import java.util.List; import java.util.logging.Logger; +import static hudson.model.Result.FAILURE; + /** * A build of a {@link Project}. * @@ -110,9 +112,9 @@ public abstract class Build
,B extends Build
> protected class RunnerImpl extends AbstractRunner { protected Result doRun(BuildListener listener) throws Exception { if(!preBuild(listener,project.getBuilders())) - return Result.FAILURE; + return FAILURE; if(!preBuild(listener,project.getPublishers())) - return Result.FAILURE; + return FAILURE; Result r = null; try { @@ -125,12 +127,12 @@ public abstract class Build
,B extends Build
> for( BuildWrapper w : wrappers ) { Environment e = w.setUp((AbstractBuild,?>)Build.this, launcher, listener); if(e==null) - return (r = Result.FAILURE); + return (r = FAILURE); buildEnvironments.add(e); } if(!build(listener,project.getBuilders())) - r = Result.FAILURE; + r = FAILURE; } finally { if (r != null) setResult(r); // tear down in reverse order @@ -142,21 +144,24 @@ public abstract class Build
,B extends Build
>
}
buildEnvironments = null;
// WARNING The return in the finally clause will trump any return before
- if (failed) return Result.FAILURE;
+ if (failed) return FAILURE;
}
return r;
}
public void post2(BuildListener listener) throws IOException, InterruptedException {
- performAllBuildStep(listener, project.getPublishers(),true);
- performAllBuildStep(listener, project.getProperties(),true);
+ if (!performAllBuildStep(listener, project.getPublishers(), true))
+ setResult(FAILURE);
+ if (!performAllBuildStep(listener, project.getProperties(), true))
+ setResult(FAILURE);
}
@Override
public void cleanUp(BuildListener listener) throws Exception {
- performAllBuildStep(listener, project.getPublishers(),false);
- performAllBuildStep(listener, project.getProperties(),false);
+ // at this point it's too late to mark the build as a failure, so ignore return value.
+ performAllBuildStep(listener, project.getPublishers(), false);
+ performAllBuildStep(listener, project.getProperties(), false);
BuildTrigger.execute(Build.this, listener);
}
diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java
index 47c2d192f2..6e04a45d1d 100644
--- a/core/src/main/java/hudson/model/Run.java
+++ b/core/src/main/java/hudson/model/Run.java
@@ -1181,7 +1181,7 @@ public abstract class Run