How to Publish JUnit and Coverage in Jenkins
The junit step ingests test XML and recordCoverage publishes coverage so both render on the build page.
Have your tools emit JUnit XML and a coverage report (Cobertura or JaCoCo), then publish both in a post block so results show even when tests fail.
Publish in a post block
A post { always } block publishes results regardless of pass or fail.
Jenkinsfile
pipeline {
agent any
stages {
stage('Test') {
steps { sh 'npm run test:ci' }
}
}
post {
always {
junit 'reports/junit/*.xml'
recordCoverage(tools: [[parser: 'COBERTURA', pattern: 'coverage/cobertura-coverage.xml']])
}
}
}Notes
- Putting publishers in post { always } ensures reports appear even on failing builds.
- recordCoverage comes from the Coverage plugin and supports JaCoCo, Cobertura, and others.
- junit marks the build unstable when tests fail, distinct from a hard failure.
Related guides
How to Run Stages in Parallel in a Jenkins PipelineRun independent Jenkins pipeline stages at the same time with a parallel block, so lint, unit, and integratio…
How to Archive Build Artifacts in a Jenkins PipelineSave build outputs in Jenkins with archiveArtifacts so binaries, bundles, and reports attach to the build and…