-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched the mechanism to collect test reports from pipeline builds
In case 'junitReport' are invoked multiple times, avoid overreporting. See https://cloudbees.atlassian.net/wiki/spaces/PRODUCT/pages/4757815355/Investigation+The+issue+of+multiple+posts+being
- Loading branch information
Showing
2 changed files
with
40 additions
and
36 deletions.
There are no files selected for viewing
36 changes: 0 additions & 36 deletions
36
src/main/java/io/jenkins/plugins/launchable/GraphListenerImpl.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/io/jenkins/plugins/launchable/RunListenerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.jenkins.plugins.launchable; | ||
|
||
import hudson.Extension; | ||
import hudson.model.listeners.RunListener; | ||
import org.jenkinsci.plugins.workflow.flow.GraphListener; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
|
||
import javax.inject.Inject; | ||
import java.util.logging.Logger; | ||
|
||
import static java.util.logging.Level.*; | ||
|
||
/** | ||
* Records test results reported into {@link WorkflowRun}. | ||
* | ||
* <p> | ||
* Our earlier attempt to implement {@link GraphListener} backfired, as when 'junitReport' step was called | ||
* multiple times, we end up reporting all test results accumulated up to that point, resulting in duplicate | ||
* data reporting. | ||
* | ||
* <p> | ||
* This approach defers the data ingestion all the way down to the end of a workflow run. | ||
*/ | ||
@Extension | ||
public class RunListenerImpl extends RunListener<WorkflowRun> { | ||
@Inject | ||
Ingester ingester; | ||
|
||
@Override | ||
public void onFinalized(WorkflowRun run) { | ||
try { | ||
ingester.slurp(run.getRootDir(), new PropsBuilder<>(run)); | ||
} catch (Exception e) { | ||
// Priority #1: Do no harm to people's build | ||
LOGGER.log(WARNING, "Failed to send JUnit result to Launchable", e); | ||
} | ||
} | ||
|
||
private static final Logger LOGGER = Logger.getLogger("io.jenkins.plugins.launchable.RunListenerImpl"); | ||
} |