Filip Stachowiak
Filip Stachowiak

Reputation: 375

What's publishHtml reportFiles parameter syntax

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?

Upvotes: 14

Views: 18798

Answers (6)

felipecrs
felipecrs

Reputation: 712

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,
])

Upvotes: 3

Abhijit Sarkar
Abhijit Sarkar

Reputation: 24548

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.

Upvotes: 0

Shaunak Sontakke
Shaunak Sontakke

Reputation: 1270

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

Upvotes: 2

Sebien
Sebien

Reputation: 881

If you have several HTML files but do not know their name nor count in advance, you can do such code:

script {
    def htmlFiles
    dir ('reports') {
        htmlFiles = findFiles glob: '*.html'
    }
    publishHTML([
            reportDir: 'reports',
            reportFiles: htmlFiles.join(','),
            reportName: 'Newman Collection Results',
            allowMissing: true,
            alwaysLinkToLastBuild: true,
            keepAll: true])
}

Notice the script section as Jenkins does not allow to declare variable in stage or steps section.

Upvotes: 19

Kru
Kru

Reputation: 71

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

Upvotes: 0

burnettk
burnettk

Reputation: 14047

"you can specify multiple comma-separated pages and each will be a tab on the report page" (from the plugin docs).

so i think it's:

reportFiles: 'test.html,other.html'

can it support wildcards like *.html? no, but there are some workarounds at https://issues.jenkins-ci.org/browse/JENKINS-7139.

Upvotes: 14

Related Questions