0
0
Jenkinsdevops~10 mins

HTML reports publishing in Jenkins - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - HTML reports publishing
Start Jenkins Job
Run Tests or Build
Generate HTML Report Files
Archive HTML Reports
Publish HTML Reports Plugin
View Reports in Jenkins UI
End
This flow shows how Jenkins runs a job, generates HTML reports, archives them, publishes via plugin, and then displays them in the Jenkins interface.
Execution Sample
Jenkins
pipeline {
  agent any
  stages {
    stage('Test') {
      steps {
        sh 'run-tests.sh'
      }
    }
  }
  post {
    always {
      publishHTML(target: [
        reportDir: 'reports',
        reportFiles: 'index.html',
        reportName: 'Test Report'
      ])
    }
  }
}
This Jenkins pipeline runs tests, then publishes the HTML report located in 'reports/index.html' using the publishHTML plugin.
Process Table
StepActionFiles CreatedJenkins Plugin ActionResult
1Start Jenkins Job--Job starts running
2Run tests via shell scriptTest output files, including HTML report files in 'reports/'-Tests run and generate report files
3Archive HTML reportsreports/index.htmlpublishHTML plugin archives report filesReports archived for publishing
4Publish HTML reportsreports/index.htmlpublishHTML plugin processes reportReport becomes visible in Jenkins UI
5View report in Jenkins UI--User can open 'Test Report' link to see HTML report
6Job ends--Job completes successfully
💡 Job ends after publishing and viewing HTML reports
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
Job StatusNot startedRunningRunningRunningCompleted
Report FilesNonereports/index.html createdreports/index.html archivedreports/index.html publishedreports/index.html published and viewable
publishHTML Plugin StateInactiveInactiveArchivingPublishingPublished
Key Moments - 3 Insights
Why do we need to specify 'reportDir' and 'reportFiles' in the publishHTML step?
Because Jenkins needs to know where to find the HTML report files to archive and publish them. See execution_table step 3 where 'reports/index.html' is archived based on these settings.
What happens if the HTML report files are not generated before publishing?
The publishHTML plugin will fail to find the files and the report won't be published. This is shown in execution_table step 2 and 3 where report files must exist before archiving.
Can the published HTML report be viewed immediately after the job finishes?
Yes, once the publishHTML plugin processes the files (step 4), the report link appears in Jenkins UI for viewing (step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at which step are the HTML report files archived?
AStep 2
BStep 4
CStep 3
DStep 5
💡 Hint
Check the 'Jenkins Plugin Action' column for archiving action in step 3.
According to the variable tracker, what is the state of 'publishHTML Plugin State' after step 4?
APublishing
BArchiving
CInactive
DPublished
💡 Hint
Look at the 'publishHTML Plugin State' row and the column 'After Step 4'.
If the 'reportDir' is set incorrectly, what will happen according to the execution flow?
AThe job will fail to start
BThe publishHTML plugin will not find the report files and fail to publish
CTests will not run
DThe report will be published but empty
💡 Hint
Refer to key_moments question about specifying 'reportDir' and 'reportFiles'.
Concept Snapshot
Jenkins HTML Reports Publishing:
- Run tests/build that generate HTML reports
- Use publishHTML plugin in post step
- Specify reportDir and reportFiles
- Plugin archives and publishes reports
- Reports viewable in Jenkins UI after job completes
Full Transcript
This visual execution shows how Jenkins publishes HTML reports. First, the Jenkins job starts and runs tests that generate HTML report files in a directory like 'reports/'. Next, the publishHTML plugin archives these files by specifying the directory and file names. Then, the plugin publishes the reports so they appear as clickable links in the Jenkins UI. Finally, users can view the HTML reports directly from Jenkins after the job finishes. Key points include ensuring the report files exist before publishing and correctly setting the report directory and file names in the plugin configuration.