What's publishHtml reportFiles parameter syntax

Viewed 12720

I'm trying to configure HTML Publisher plugin for Jenkins via Jenkinsfile to publish few html files like this:

    publishHTML(
        target: [
              allowMissing         : false,
              alwaysLinkToLastBuild: false,
              keepAll              : true,
              reportDir            : 'my-project-grails/build/reports/codenarc',
              reportFiles          : 'test.html',
              reportName           : "Codenarc Report"
        ]
    )

The description of the reportFiles parameter here says I should be able to specify multiple files. But what's the syntax?

6 Answers

As Sebien's answer but:

  • Uses a one-liner for the files filter
  • No need to be inside a script block
  • Incorporates Abhijit's answer
publishHTML([
  reportName: 'Newman Report'
  reportDir: 'reports',
  reportFiles: "${dir('reports') { findFiles(glob: '**/*.html').join(',') ?: 'Not found' }}",
  allowMissing: true,
  alwaysLinkToLastBuild: true,
  keepAll: true,
])

You can specify multiple files and their locations.

publishHTML( [ 
                allowMissing: false, 
                alwaysLinkToLastBuild: false,
                keepAll: true, 
                reportDir: 'build/reports/', 
                reportFiles: 'TestResults.html, coverage/index.html', 
                reportTitles: 'Test Results, Coverage',
                reportName: 'Test Results Left side link'
] )
  • reportFiles: First tab (Test Results) shows 1st reportFiles - TestResults.html while second tab (Coverage) shows 2nd reportFiles - coverage/index.html.
  • reportTitles: Here reportTitles are name of the tabs.
  • reportName is the link seen on job's page which links to the published html.

enter image description here

In Original Question there is syntax issue. Missing "," after --> reportFiles : 'test.html' This is causing DSL interpreter to expect another HTML file

Sebien's answer using findFiles works, but it comes with a big gotcha. findFiles return an array, which if empty and joined, returns an empty string causing all files under the workspace to be published. To avoid this, do the following:

def htmlFiles = findFiles glob: '*.html'
htmlFiles = htmlFiles.join(",") ?: "Not Found"

and set allowMissing: true. There's also no need to define htmlFiles inside dir ('reports') closure.

Related