Skip to content
Latchkey

How to Publish JUnit Test Results in a Jenkins Pipeline

The junit step parses JUnit XML into the Jenkins Tests tab and trend graph - run it in post { always }.

Have tests emit JUnit XML, then call the junit step to publish it. Put it in a post { always } block so the report appears even when the test step fails.

Publish results in post-always

The junit step runs regardless of the test outcome, so failed tests still show in the UI.

Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'npm ci && npm test -- --reporters=jest-junit'
      }
    }
  }
  post {
    always {
      junit 'reports/junit.xml'
    }
  }
}

Gotchas

  • Call junit in post { always } - if you put it only after the test step, a test failure skips publishing.
  • The junit step (JUnit plugin) marks the build unstable on failed tests, distinct from a hard failure.
  • Point the glob at the actual report path; an empty match makes the step error unless you set allowEmptyResults: true.

Related guides

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