Skip to content

Commit 08f725b

Browse files
authored
fix JENKINS-70171: publisher exceptions are catched, doesn't result in failing builds (#562)
1 parent 75a2415 commit 08f725b

File tree

8 files changed

+45
-34
lines changed

8 files changed

+45
-34
lines changed

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/ConcordionTestsPublisher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import hudson.Extension;
2424
import hudson.FilePath;
2525
import hudson.Launcher;
26+
import hudson.model.Result;
2627
import hudson.model.Run;
2728
import hudson.model.StreamBuildListener;
2829
import hudson.model.TaskListener;
@@ -141,8 +142,9 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
141142
"\" with the following files: " + target.getReportFiles());
142143
HtmlPublisher.publishReports(run, workspace, listener, Collections.singletonList(target), HtmlPublisher.class);
143144
} catch (final Exception e) {
144-
listener.error("[withMaven] concordionPublisher - Silently ignore exception archiving Concordion reports: " + e);
145+
listener.error("[withMaven] concordionPublisher - exception archiving Concordion reports: " + e + ". Failing the build.");
145146
LOGGER.log(Level.WARNING, "Exception processing Concordion reports archiving", e);
147+
run.setResult(Result.FAILURE);
146148
}
147149
}
148150

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/FindbugsAnalysisPublisher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import hudson.Extension;
2828
import hudson.FilePath;
2929
import hudson.Launcher;
30+
import hudson.model.Result;
3031
import hudson.model.Run;
3132
import hudson.model.StreamBuildListener;
3233
import hudson.model.TaskListener;
@@ -233,9 +234,10 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
233234
try {
234235
findBugsPublisher.perform(run, workspace, launcher, listener);
235236
} catch (Exception e) {
236-
listener.error("[withMaven] findbugsPublisher - Silently ignore exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
237-
pluginInvocation + ": " + e);
237+
listener.error("[withMaven] findbugsPublisher - exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
238+
pluginInvocation + ": " + e + ". Failing the build.");
238239
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(findBugsTestEvent), e);
240+
run.setResult(Result.FAILURE);
239241
}
240242

241243
}

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/InvokerRunsPublisher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import hudson.Extension;
2828
import hudson.FilePath;
2929
import hudson.Launcher;
30+
import hudson.model.Result;
3031
import hudson.model.Run;
3132
import hudson.model.StreamBuildListener;
3233
import hudson.model.TaskListener;
@@ -140,8 +141,9 @@ private void executeReporter(StepContext context, TaskListener listener, List<El
140141
try {
141142
archiver.perform(run, workspace, launcher, listener, node);
142143
} catch (Exception e) {
143-
listener.error("[withMaven] invokerPublisher - Silently ignore exception archiving Invoker runs for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + e);
144+
listener.error("[withMaven] invokerPublisher - exception archiving Invoker runs for Maven artifact " + mavenArtifact.toString() + " generated by " + pluginInvocation + ": " + e + ". Failing the build.");
144145
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(testEvent), e);
146+
run.setResult(Result.FAILURE);
145147
}
146148

147149
}

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/JGivenTestsPublisher.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,32 @@
1818

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

21-
import hudson.Extension;
22-
import hudson.FilePath;
23-
import hudson.Launcher;
24-
import hudson.model.Run;
25-
import hudson.model.StreamBuildListener;
26-
import hudson.model.TaskListener;
27-
import org.jenkinsci.Symbol;
28-
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator;
29-
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
30-
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
31-
import org.jenkinsci.plugins.workflow.steps.StepContext;
32-
import org.kohsuke.stapler.DataBoundConstructor;
33-
import org.w3c.dom.Element;
21+
import static org.jenkinsci.plugins.pipeline.maven.publishers.DependenciesLister.listDependencies;
3422

35-
import javax.annotation.Nonnull;
3623
import java.io.IOException;
3724
import java.io.OutputStream;
3825
import java.util.ArrayList;
3926
import java.util.Set;
4027
import java.util.logging.Level;
4128
import java.util.logging.Logger;
4229

43-
import static org.jenkinsci.plugins.pipeline.maven.publishers.DependenciesLister.listDependencies;
30+
import javax.annotation.Nonnull;
31+
32+
import org.jenkinsci.Symbol;
33+
import org.jenkinsci.plugins.jgiven.JgivenReportGenerator;
34+
import org.jenkinsci.plugins.pipeline.maven.MavenDependency;
35+
import org.jenkinsci.plugins.pipeline.maven.MavenPublisher;
36+
import org.jenkinsci.plugins.workflow.steps.StepContext;
37+
import org.kohsuke.stapler.DataBoundConstructor;
38+
import org.w3c.dom.Element;
39+
40+
import hudson.Extension;
41+
import hudson.FilePath;
42+
import hudson.Launcher;
43+
import hudson.model.Result;
44+
import hudson.model.Run;
45+
import hudson.model.StreamBuildListener;
46+
import hudson.model.TaskListener;
4447

4548
/**
4649
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a>
@@ -91,7 +94,8 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
9194
}
9295
if (!foundJGivenDependency) {
9396
if (LOGGER.isLoggable(Level.FINE)) {
94-
listener.getLogger().println("[withMaven] jgivenPublisher - JGiven not found within your project dependencies, aborting.");
97+
listener.getLogger().println(
98+
"[withMaven] jgivenPublisher - JGiven not found within your project dependencies, aborting.");
9599
}
96100
return;
97101
}
@@ -113,8 +117,9 @@ public void process(@Nonnull final StepContext context, @Nonnull final Element m
113117
generator.perform(run, workspace, launcher, listener);
114118
} catch (final Exception e) {
115119
listener.error(
116-
"[withMaven] jgivenPublisher - Silently ignore exception archiving JGiven reports: " + e);
120+
"[withMaven] jgivenPublisher - exception archiving JGiven reports: " + e + ". Failing the build.");
117121
LOGGER.log(Level.WARNING, "Exception processing JGiven reports archiving", e);
122+
run.setResult(Result.FAILURE);
118123
}
119124
}
120125

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/JacocoReportPublisher.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import hudson.Extension;
2828
import hudson.FilePath;
2929
import hudson.Launcher;
30+
import hudson.model.Result;
3031
import hudson.model.Run;
3132
import hudson.model.TaskListener;
3233
import hudson.plugins.jacoco.JacocoPublisher;
@@ -219,15 +220,9 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
219220
try {
220221
jacocoPublisher.perform(run, workspace, launcher, listener);
221222
} catch (Exception e) {
222-
listener.error("[withMaven] jacocoPublisher - Silently ignore exception archiving JaCoCo results for " + jacocoReportDetails);
223-
listener.error("[withMaven] jacocoPublisher - Silently ignore exception archiving JaCoCo results: " + e);
224-
225-
if (LOGGER.isLoggable(Level.FINE)) {
226-
StringWriter buffer = new StringWriter();
227-
PrintWriter printWriter = new PrintWriter(buffer);
228-
e.printStackTrace(printWriter);
229-
listener.error(buffer.toString());
230-
}
223+
listener.error("[withMaven] jacocoPublisher - exception archiving JaCoCo results for " + jacocoReportDetails + ": " + e + ". Failing the build.");
224+
LOGGER.log(Level.WARNING, "Exception processing JaCoCo results", e);
225+
run.setResult(Result.FAILURE);
231226
}
232227
}
233228

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/JunitTestsPublisher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,9 @@ private void executeReporter(StepContext context, TaskListener listener, List<El
367367
run.setResult(Result.UNSTABLE);
368368
}
369369
} catch (RuntimeException e) {
370-
listener.error("[withMaven] junitPublisher - Silently ignore exception archiving JUnit results:" + testResults + ": " + e);
370+
listener.error("[withMaven] junitPublisher - exception archiving JUnit results " + testResults + ": " + e + ". Failing the build.");
371371
LOGGER.log(Level.WARNING, "Exception processing " + testResults, e);
372+
run.setResult(Result.FAILURE);
372373
}
373374
}
374375

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/SpotBugsAnalysisPublisher.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import hudson.Extension;
2828
import hudson.FilePath;
2929
import hudson.Launcher;
30+
import hudson.model.Result;
3031
import hudson.model.Run;
3132
import hudson.model.TaskListener;
3233
import hudson.plugins.findbugs.FindBugsPublisher;
@@ -234,9 +235,10 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
234235
try {
235236
findBugsPublisher.perform(run, workspace, launcher, listener);
236237
} catch (Exception e) {
237-
listener.error("[withMaven] SpotBugsPublisher - Silently ignore exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
238-
pluginInvocation + ": " + e);
238+
listener.error("[withMaven] SpotBugsPublisher - exception archiving FindBugs results for Maven artifact " + mavenArtifact.toString() + " generated by " +
239+
pluginInvocation + ": " + e + ". Failing the build.");
239240
LOGGER.log(Level.WARNING, "Exception processing " + XmlUtils.toString(findBugsTestEvent), e);
241+
run.setResult(Result.FAILURE);
240242
}
241243

242244
}

jenkins-plugin/src/main/java/org/jenkinsci/plugins/pipeline/maven/publishers/TasksScannerPublisher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import hudson.Extension;
44
import hudson.FilePath;
55
import hudson.Launcher;
6+
import hudson.model.Result;
67
import hudson.model.Run;
78
import hudson.model.StreamBuildListener;
89
import hudson.model.TaskListener;
@@ -169,8 +170,9 @@ public void process(@Nonnull StepContext context, @Nonnull Element mavenSpyLogsE
169170
try {
170171
tasksPublisher.perform(run, workspace, launcher, listener);
171172
} catch (Exception e) {
172-
listener.error("[withMaven] openTasksPublisher - Silently ignore exception scanning tasks in " + pattern + ": " + e);
173+
listener.error("[withMaven] openTasksPublisher - exception scanning tasks in " + pattern + ": " + e + ". Failing the build.");
173174
LOGGER.log(Level.WARNING, "Exception scanning tasks in " + pattern, e);
175+
run.setResult(Result.FAILURE);
174176
}
175177
}
176178

0 commit comments

Comments
 (0)