Skip to content
Latchkey

How to Publish an HTML Report in a Jenkins Pipeline

publishHTML (HTML Publisher plugin) attaches a generated HTML report directory to the build for browsing in the UI.

Install the HTML Publisher plugin, then call publishHTML(target: [...]) pointing at the report directory and index file. A link appears on the build and job pages.

Steps

  • Install the HTML Publisher plugin.
  • Generate the report into a directory (e.g. coverage/).
  • Call publishHTML with reportDir, reportFiles, and reportName.

Jenkinsfile

Jenkinsfile
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'npm test -- --coverage'
      }
      post {
        always {
          publishHTML(target: [
            reportDir: 'coverage/lcov-report',
            reportFiles: 'index.html',
            reportName: 'Coverage Report',
            keepAll: true,
            alwaysLinkToLastBuild: true
          ])
        }
      }
    }
  }
}

Gotchas

  • The default Content Security Policy can break report CSS/JS; adjust the Jenkins CSP if styles are missing.
  • Set keepAll: true to retain the report on historical builds, not just the latest.

Related guides

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