Skip to content
Latchkey

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

Run this faster and cheaper on Latchkey managed runners. Start free →