Publishing HTML Reports in Jenkins Pipeline

It shows the usage of HTML Publisher plugin to see reports generated using integrated tools like sonaryqube , codecoverage , protractor.. .

Using this jenkins plugin we can see the reports from within jenkins.

We will use sample ruby project , and will create jenkins pipeline for it. we are doing code coverage over this project and will publish the code coverage results with each build job. I could.

STEPS INVOLVED

Configure your pipeline under Jenkins

1. Creation of Pipeline Project

Go to NEW ITEM under Jenkins and choose appropriate name for the project and choose project type as pipeline.

1

Go to the Pipeline section of Advance Project Options and enter below code :-

stage ‘Build’

node {
// Checkout
git branch: ‘master’,url: ‘https://github.com/devops81/HTMLPublisher.git’

// 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’)

}

2

Till this point if we build the project it will do following things

i) Checkout the codebase
ii)Execute the bundle install command
iii)Execute the command bundle exec rake build spec which will compile test and generate the artifact file

2. Generating pipeline code for HTML Publisher plugin

Next we will use Snippet Generator  to generate code for HTML Publisher plugin go to the url :-

Under SAMPLE STEP choose publishHTML:Publish HTML reports and provide the values for these fields :-

  • HTML directory to archive
  • Index page[s]
  • Report title

3

Next click on Generate Pipeline Script it will generate script for the html publisher plugin with the provided values.

3. Integrating the generated html publisher code with existing pipeline code

Next we will copy the code which got generated and will append it to our existing pipeline code

4

Final code should look like below

stage ‘Build’

node {
// Checkout
git branch: ‘master’,url: ‘https://github.com/devops81/HTMLPublisher.git’

// 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’)

publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: ‘coverage’, reportFiles: ‘index.html’, reportName: ‘HTML Report’, reportTitles: ‘Coverage Report’])
}

After click on Apply and Save button on Jenkins.

4. Viewing the report post successful Jenkins job run

Next we can run the job post successful run of the job  the left section of the Jenkins should show link for html report got generated during the build.

5

 

So this link should show us the coverage report generated from within Jenkins.

6.png

2 thoughts on “Publishing HTML Reports in Jenkins Pipeline

Leave a Reply