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 buildSteps, boolean phase) throws InterruptedException, IOException { - performAllBuildStep(listener,buildSteps.values(),phase); + protected final boolean performAllBuildStep(BuildListener listener, Map 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 buildSteps, boolean phase) throws InterruptedException, IOException { + protected final boolean performAllBuildStep(BuildListener listener, Iterable 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 ,RunT extends Run - * This method is called after the status of the build is determined. + * This method is called after {@linkplain #run(BuildListener) the main portion of the build is completed.} * This is a good opportunity to do notifications based on the result * of the build. When this method is called, the build is not really * finalized yet, and the build is still considered in progress --- for example, diff --git a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java index e7c003f6c5..9bd8420824 100644 --- a/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java +++ b/maven-plugin/src/main/java/hudson/maven/MavenModuleSetBuild.java @@ -83,6 +83,8 @@ import org.apache.maven.project.ProjectBuildingException; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; +import static hudson.model.Result.FAILURE; + /** * {@link Build} for {@link MavenModuleSet}. * @@ -592,8 +594,11 @@ public class MavenModuleSetBuild extends AbstractMavenBuild