DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Concourse CI/CD Pipeline: Webhook Triggers
  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last

Trending

  • How to Convert XLS to XLSX in Java
  • Unlocking AI Coding Assistants: Generate Unit Tests
  • Unlocking the Potential of Apache Iceberg: A Comprehensive Analysis
  • Measuring the Impact of AI on Software Engineering Productivity
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. DevOps and CI/CD
  4. Publishing HTML Reports in Pipeline

Publishing HTML Reports in Pipeline

Liam Newman shows you how you can use the HTML Publisher Plugin instead of writing a custom plugin for each type of report.

By 
Liam Newman user avatar
Liam Newman
·
Nov. 07, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
39.0K Views

Join the DZone community and get the full member experience.

Join For Free

Most projects need more than just JUnit result reporting. Rather than writing a custom plugin for each type of report, we can use the HTML Publisher Plugin.

Let's Make This Quick

I've found a Ruby project, Hermann, that I'd like to build using Jenkins Pipeline. I'd also like to have the code coverage results published with each build job. I could write a plugin to publish this data, but I'm in a bit of a hurry and the build already creates an HTML report file using SimpleCov when the unit tests run.

Simple Build

I'm going to use the HTML Publisher Plugin to add the HTML-formatted code coverage report to my builds. Here's a simple pipeline for building the Hermann project:

 stage 'Build'
 
 node {
   // Checkout
   checkout scm
 
   // install required bundles
   sh 'bundle install'
 
   // build and run tests with coverage
   sh 'bundle exec rake build spec'
 
   // Archive the built artifacts
   archive (includes: 'pkg/*.gem')
 }

Note: This pipeline expects to be run from a Jenkinsfile in SCM. To copy and paste it directly into a Jenkins Pipeline job, replace the checkout scm step with git 'https://github.com/reiseburo/hermann.git'.

Simple enough. It builds and runs tests and archives the package.

Job Run Without Report Link

Now, I just need to add the step to publish the code coverage report. I know that rake spec creates an index.html file in the coverage directory. I've already installed the HTML Publisher Plugin. How do I add the HTML publishing step to the pipeline? The plugin page doesn't say anything about it.

Snippet Generator to the Rescue

Documentation is hard to maintain and easy to miss, even more so in a system like Jenkins with hundreds of plugins with each potentially having one or more Groovy fixtures to add to the Pipeline. The Pipeline Syntax Snippet Generator helps users navigate this jungle by providing a way to generate a code snippet for any step using provided inputs.

It offers a dynamically generated list of steps based on the installed plugins. From that list, I select the publishHTML step:

Snippet Generator Menu

Then, it shows me a UI similar to the one used in job configuration. I fill in the fields and click Generate and it shows me a snippet of Groovy generated from that input.

Snippet Generator Output

HTML Published

I can use that snippet directly or as a template for further customization. In this case, I'll just reformat and copy it in at the end of my pipeline. (I ran into a minor bug in the snippet generated for this plugin step. Typing error string in my search bar immediately found the bug and a workaround.)

   /* ...unchanged... */
 
   // Archive the built artifacts
   archive (includes: 'pkg/*.gem')
 
   // publish html
   // snippet generator doesn't include "target:"
   // https://issues.jenkins-ci.org/browse/JENKINS-29711.
   publishHTML (target: [
       allowMissing: false,
       alwaysLinkToLastBuild: false,
       keepAll: true,
       reportDir: 'coverage',
       reportFiles: 'index.html',
       reportName: "RCov Report"
     ])
 
 }

When I run this new pipeline, I am rewarded with an RCov Report link on left side that I can follow to show the HTML report.

Job Run With Report Link

RCov Report

I even added the keepAll setting to let me go back and look at reports on old jobs as more come in. As I said in the beginning, this is not as slick as what I could do with a custom plugin, but it is much easier and works with any static HTML.

HTML Pipeline (software)

Published at DZone with permission of Liam Newman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Concourse CI/CD Pipeline: Webhook Triggers
  • Automating Data Pipelines: Generating PySpark and SQL Jobs With LLMs in Cloudera
  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • The 4 R’s of Pipeline Reliability: Designing Data Systems That Last

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!