Skip to content

Commit

Permalink
Use JUnitResultArchiver#parseAndSummarize method which supports the J…
Browse files Browse the repository at this point in the history
…enkins JUnit SQL storage. (#558)

Co-authored-by: Gong Yi <[email protected]>
  • Loading branch information
topikachu and Gong Yi authored Nov 21, 2022
1 parent cd910e4 commit 2dbddd9
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import hudson.model.TaskListener;
import hudson.tasks.junit.JUnitResultArchiver;
import hudson.tasks.junit.TestDataPublisher;
import hudson.tasks.junit.TestResultAction;
import hudson.tasks.junit.TestResultSummary;
import hudson.tasks.junit.pipeline.JUnitResultsStepExecution;
import hudson.tasks.test.PipelineTestDetails;
import org.jenkinsci.Symbol;
Expand Down Expand Up @@ -347,23 +347,23 @@ private void executeReporter(StepContext context, TaskListener listener, List<El
if (LOGGER.isLoggable(Level.FINER)) {
listener.getLogger().println("[withMaven] junitPublisher - collect test reports: testResults=" + archiver.getTestResults() + ", healthScaleFactor=" + archiver.getHealthScaleFactor());
}
TestResultAction testResultAction = JUnitResultArchiver.parseAndAttach(archiver, pipelineTestDetails, run, workspace, launcher, listener);
TestResultSummary testResultSummary = JUnitResultArchiver.parseAndSummarize(archiver, pipelineTestDetails, run, workspace, launcher, listener);

if (testResultAction == null) {
if (testResultSummary == null) {
// no unit test results found
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] junitPublisher - no unit test results found, ignore");
}
} else if (testResultAction.getResult().getFailCount() == 0) {
} else if (testResultSummary.getFailCount() == 0) {
// unit tests are all successful
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] junitPublisher - unit tests are all successful");
}
} else {
if (LOGGER.isLoggable(Level.FINE)) {
listener.getLogger().println("[withMaven] junitPublisher - " + testResultAction.getResult().getFailCount() + " unit test failure(s) found, mark job as unstable");
listener.getLogger().println("[withMaven] junitPublisher - " + testResultSummary.getFailCount() + " unit test failure(s) found, mark job as unstable");
}
node.addAction(new WarningAction(Result.UNSTABLE).withMessage(testResultAction.getResult().getFailCount() + " unit test failure(s) found"));
node.addAction(new WarningAction(Result.UNSTABLE).withMessage(testResultSummary.getFailCount() + " unit test failure(s) found"));
run.setResult(Result.UNSTABLE);
}
} catch (RuntimeException e) {
Expand Down

0 comments on commit 2dbddd9

Please sign in to comment.