Skip to content

Commit

Permalink
fix JENKINS-70171: publisher exceptions are catched, doesn't result i…
Browse files Browse the repository at this point in the history
…n failing builds (#562)
  • Loading branch information
bguerin authored Dec 5, 2022
1 parent 75a2415 commit 08f725b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -141,8 +142,9 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
"\" with the following files: " + target.getReportFiles());
HtmlPublisher.publishReports(run, workspace, listener, Collections.singletonList(target), HtmlPublisher.class);
} catch (final Exception e) {
listener.error("[withMaven] concordionPublisher - Silently ignore exception archiving Concordion reports: " + e);
listener.error("[withMaven] concordionPublisher - exception archiving Concordion reports: " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing Concordion reports archiving", e);
run.setResult(Result.FAILURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -233,9 +234,10 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
try {
findBugsPublisher.perform(run, workspace, launcher, listener);
} catch (Exception e) {
listener.error("[withMaven] findbugsPublisher - Silently ignore exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
pluginInvocation + ": " + e);
listener.error("[withMaven] findbugsPublisher - exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
pluginInvocation + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(findBugsTestEvent), e);
run.setResult(Result.FAILURE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -140,8 +141,9 @@ private void executeReporter(StepContext context, TaskListener listener, List<El
try {
archiver.perform(run, workspace, launcher, listener, node);
} catch (Exception e) {
listener.error("[withMaven] invokerPublisher - Silently ignore exception archiving Invoker runs for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + e);
listener.error("[withMaven] invokerPublisher - exception archiving Invoker runs for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(testEvent), e);
run.setResult(Result.FAILURE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,32 @@

package org.jenkinsci.plugins.pipeline.maven.publishers;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
import org.w3c.dom.Element;
import static org.jenkinsci.plugins.pipeline.maven.publishers.DependenciesLister.listDependencies;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.jenkinsci.plugins.pipeline.maven.publishers.DependenciesLister.listDependencies;
import javax.annotation.Nonnull;

import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator;
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
import org.jenkinsci.plugins.workflow.steps.StepContext;
import org.kohsuke.stapler.DataBoundConstructor;
import org.w3c.dom.Element;

import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;

/**
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
Expand Down Expand Up @@ -91,7 +94,8 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
}
if (!foundJGivenDependency) {
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] jgivenPublisher - JGiven not found within your project dependencies, aborting.");
listener.getLogger().println(
"[withMaven] jgivenPublisher - JGiven not found within your project dependencies, aborting.");
}
return;
}
Expand All @@ -113,8 +117,9 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
generator.perform(run, workspace, launcher, listener);
} catch (final Exception e) {
listener.error(
"[withMaven] jgivenPublisher - Silently ignore exception archiving JGiven reports: " + e);
"[withMaven] jgivenPublisher - exception archiving JGiven reports: " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing JGiven reports archiving", e);
run.setResult(Result.FAILURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.jacoco.JacocoPublisher;
Expand Down Expand Up @@ -219,15 +220,9 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
try {
jacocoPublisher.perform(run, workspace, launcher, listener);
} catch (Exception e) {
listener.error("[withMaven] jacocoPublisher - Silently ignore exception archiving JaCoCo results for " + jacocoReportDetails);
listener.error("[withMaven] jacocoPublisher - Silently ignore exception archiving JaCoCo results: " + e);

if (LOGGER.isLoggable(Level.FINE)) {
StringWriter buffer = new StringWriter();
PrintWriter printWriter = new PrintWriter(buffer);
e.printStackTrace(printWriter);
listener.error(buffer.toString());
}
listener.error("[withMaven] jacocoPublisher - exception archiving JaCoCo results for " + jacocoReportDetails + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing JaCoCo results", e);
run.setResult(Result.FAILURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ private void executeReporter(StepContext context, TaskListener listener, List<El
run.setResult(Result.UNSTABLE);
}
} catch (RuntimeException e) {
listener.error("[withMaven] junitPublisher - Silently ignore exception archiving JUnit results:" + testResults + ": " + e);
listener.error("[withMaven] junitPublisher - exception archiving JUnit results " + testResults + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing " + testResults, e);
run.setResult(Result.FAILURE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.findbugs.FindBugsPublisher;
Expand Down Expand Up @@ -234,9 +235,10 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
try {
findBugsPublisher.perform(run, workspace, launcher, listener);
} catch (Exception e) {
listener.error("[withMaven] SpotBugsPublisher - Silently ignore exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
pluginInvocation + ": " + e);
listener.error("[withMaven] SpotBugsPublisher - exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
pluginInvocation + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(findBugsTestEvent), e);
run.setResult(Result.FAILURE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.StreamBuildListener;
import hudson.model.TaskListener;
Expand Down Expand Up @@ -169,8 +170,9 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
try {
tasksPublisher.perform(run, workspace, launcher, listener);
} catch (Exception e) {
listener.error("[withMaven] openTasksPublisher - Silently ignore exception scanning tasks in " + pattern + ": " + e);
listener.error("[withMaven] openTasksPublisher - exception scanning tasks in " + pattern + ": " + e + ". Failing the build.");
LOGGER.log(Level.WARNING, "Exception scanning tasks in " + pattern, e);
run.setResult(Result.FAILURE);
}
}

Expand Down

0 comments on commit 08f725b

Please sign in to comment.