Jenkins - Reporting
Jenkins - Publishing Reports
Section titled “Jenkins - Publishing Reports”Beyond simple pass/fail status, Jenkins can publish various reports generated during the build process, providing deeper insights into quality, coverage, and analysis.
This typically involves configuring your build or test tools to generate report files in a format Jenkins understands (or can be made to understand via plugins), and then using specific Pipeline steps or post-build actions to publish them.
Common Report Types and How to Publish Them
Section titled “Common Report Types and How to Publish Them”1. Test Results (JUnit/TestNG XML)
Section titled “1. Test Results (JUnit/TestNG XML)”- Purpose: Show detailed unit/integration/E2E test results, trends, failures, and stack traces.
- Generation: Configure your test framework (JUnit, TestNG, pytest, Jest, NUnit, etc.) and build tool (Maven Surefire/Failsafe, Gradle Test,
dotnet test,npm test) to output reports in JUnit XML format. - Jenkins Step: Use the
junitstep (from the built-in JUnit plugin). - Example (Pipeline
postblock):junit '**/target/surefire-reports/*.xml'orjunit '**/build/test-results/test/*.xml'
2. Code Coverage Reports (JaCoCo, Cobertura, etc.)
Section titled “2. Code Coverage Reports (JaCoCo, Cobertura, etc.)”- Purpose: Visualize line, branch, and method coverage achieved by tests.
- Generation: Instrument code and run tests using coverage tools integrated with your build (e.g., JaCoCo Maven/Gradle plugin, Istanbul/nyc for JavaScript, Coverage.py for Python). These tools generate XML or HTML reports.
- Jenkins Plugin: Install the ‘Code Coverage API Plugin’ plus a specific plugin for your format (e.g., ‘JaCoCo’, ‘Cobertura Coverage’).
- Jenkins Step: Use the step provided by the specific plugin (e.g.,
jacoco()orpublishCoverage adapters: [cobertura('**/target/site/cobertura/coverage.xml')]). - Example (Pipeline
postblock with JaCoCo):jacoco execPattern: '**/target/jacoco.exec', classPattern: '**/target/classes', sourcePattern: '**/src/main/java'
3. Static Analysis Reports (Checkstyle, PMD, SpotBugs, ESLint)
Section titled “3. Static Analysis Reports (Checkstyle, PMD, SpotBugs, ESLint)”- Purpose: Display violations of coding standards, potential bugs, and bad practices detected by static analysis tools.
- Generation: Run analysis tools as part of your build (e.g., Checkstyle/PMD/SpotBugs Maven/Gradle plugins, ESLint via npm scripts). Configure them to generate XML or JSON report files.
- Jenkins Plugin: Install the ‘Warnings Next Generation’ plugin. This is the modern standard, replacing older individual analysis plugins.
- Jenkins Step: Use the
recordIssuesstep, configuring the specific tool and report file pattern. - Example (Pipeline
postblock):recordIssues tools: [checkStyle(pattern: '**/target/checkstyle-result.xml'), pmdParser(pattern: '**/target/pmd.xml'), spotbugs(pattern: '**/target/spotbugsXml.xml')]
4. Generic HTML Reports
Section titled “4. Generic HTML Reports”- Purpose: Display any custom report generated in HTML format (e.g., test reports from frameworks like Cypress or Allure, documentation, analysis dashboards).
- Generation: The tool or script generating the report should produce an
index.htmlfile and associated assets (CSS, JS, images) in a specific directory. - Jenkins Plugin: Install the ‘HTML Publisher’ plugin.
- Jenkins Step: Use the
publishHTMLstep, specifying the directory containing the HTML report and the main file. - Example (Pipeline
postblock):publishHTML(target: [allowMissing: true, alwaysLinkToLastBuild: true, keepAll: false, reportDir: 'target/my-custom-report', reportFiles: 'report.html', reportName: 'My Custom Report'])
Viewing Published Reports
Section titled “Viewing Published Reports”Once published, links to these reports will appear on the build’s main page sidebar. Clicking these links will display the report integrated within the Jenkins UI (for JUnit, Coverage, Warnings NG) or navigate to the published HTML content.
These reports provide valuable feedback loops, helping developers quickly identify issues related to tests, code quality, and coverage directly from Jenkins.