📖 Scenario: You are working as a DevOps engineer. Your team runs automated tests that generate HTML reports. You want to publish these HTML reports in Jenkins so everyone can see the test results easily.
🎯 Goal: Learn how to configure a Jenkins job to publish HTML reports generated by automated tests.
📋 What You'll Learn
Create a Jenkins job configuration snippet with HTML report directory
Add a configuration variable for the report directory path
Write the Jenkins pipeline step to publish the HTML report
Print the Jenkins pipeline snippet that publishes the HTML report
💡 Why This Matters
🌍 Real World
Publishing HTML reports in Jenkins helps teams easily view test results and other reports directly in the Jenkins interface without searching files manually.
💼 Career
Knowing how to configure Jenkins to publish HTML reports is a key skill for DevOps engineers and automation specialists to improve visibility and feedback in CI/CD pipelines.
Progress0 / 4 steps
1
Create Jenkins job configuration snippet for HTML reports
Create a variable called htmlReportConfig that contains the Jenkins job configuration snippet as a string. It should include the publishHTML block with reportDir set to "target/surefire-reports" and reportFiles set to "index.html".
Jenkins
Hint
Use triple quotes to create a multi-line string. Include publishHTML with reportDir and reportFiles exactly as shown.
2
Add a configuration variable for the report directory path
Create a variable called reportDirectory and set it to the string "target/surefire-reports". Then update the htmlReportConfig string to use this variable inside the reportDir field using string interpolation.
Jenkins
Hint
Use an f-string for htmlReportConfig so you can insert the reportDirectory variable inside the string.
3
Write the Jenkins pipeline step to publish the HTML report
Create a variable called pipelineStep that contains the Jenkins pipeline step code as a string. It should call publishHTML with reportDir set to reportDirectory, reportFiles set to "index.html", and reportName set to "Test Report". Use string interpolation to insert reportDirectory.
Jenkins
Hint
Use triple quotes and an f-string to create the pipelineStep string with the correct Jenkins pipeline syntax.
4
Print the Jenkins pipeline snippet that publishes the HTML report
Write a print statement to display the contents of the pipelineStep variable.
Jenkins
Hint
Use print(pipelineStep) to show the Jenkins pipeline snippet.
Practice
(1/5)
1. What is the main purpose of publishing HTML reports in Jenkins?
easy
A. To display test and build results inside Jenkins in a readable format
B. To execute shell commands during the build
C. To send email notifications after a build
D. To create new Jenkins jobs automatically
Solution
Step 1: Understand the role of HTML reports in Jenkins
HTML reports are used to show test and build results in a user-friendly way inside Jenkins.
Step 2: Identify the correct purpose
Among the options, only displaying results inside Jenkins matches the purpose of HTML reports.
Final Answer:
To display test and build results inside Jenkins in a readable format -> Option A
Quick Check:
HTML reports = readable results inside Jenkins [OK]
Hint: HTML reports show results inside Jenkins UI [OK]
Common Mistakes:
Confusing HTML reports with build execution steps
Thinking HTML reports send notifications
Assuming HTML reports create jobs
2. Which of the following is the correct syntax to publish an HTML report in a Jenkins pipeline script?
What happens if the 'summary.html' file is missing after the build?
medium
A. The build will fail due to missing report file
B. The build will succeed and no report will be shown
C. Jenkins will create an empty report automatically
D. The build will pause and wait for the file
Solution
Step 1: Understand the allowMissing option
allowMissing: true means Jenkins will not fail the build if the report file is missing.
Step 2: Predict behavior when file is missing
Since allowMissing is true, the build succeeds but no report is shown.
Final Answer:
The build will succeed and no report will be shown -> Option B
Quick Check:
allowMissing true = no failure if missing [OK]
Hint: allowMissing true lets build pass without report [OK]
Common Mistakes:
Assuming build fails when allowMissing is true
Thinking Jenkins creates missing files
Believing build pauses for missing files
4. You configured publishHTML in your Jenkins pipeline but the HTML report does not appear in the build results. Which of these is the most likely cause?
medium
A. The Jenkins server needs a restart
B. The publishHTML step is missing the allowMissing option
C. The reportDir path is incorrect or does not contain the report files
D. The reportName is too long
Solution
Step 1: Check common reasons for missing HTML reports
If the reportDir path is wrong or empty, Jenkins cannot find the report files to display.
Step 2: Evaluate other options
allowMissing missing does not prevent report display if files exist; reportName length and server restart are unrelated.
Final Answer:
The reportDir path is incorrect or does not contain the report files -> Option C
Quick Check:
Wrong reportDir = no report shown [OK]
Hint: Verify reportDir path and files exist [OK]
Common Mistakes:
Ignoring reportDir correctness
Thinking allowMissing affects report visibility
Restarting Jenkins unnecessarily
5. You want Jenkins to keep all HTML reports from every build and always link to the latest report. Which configuration achieves this?