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
publishHTMLwithreportDir,reportFiles, andreportName.
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: trueto retain the report on historical builds, not just the latest.
Related guides
How to Continue a Pipeline After a Failure With catchError in JenkinsLet a Jenkins stage fail without aborting the whole pipeline using catchError, marking the build unstable whi…
How to Pass a Secret File to a Command in JenkinsExpose a stored Secret file credential as a temporary path with withCredentials in Jenkins, so tools like kub…