Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 830
Filip Stachowiak Avatar asked Jun 30 '17 14:06

Filip Stachowiak


People also ask

How do I archive HTML reports in Jenkins?

The HTML Publisher plugin can be configured in the post build portion of your Jenkins job. HTML directory to archive - the path to the report directory to archive relative to the workspace. Index page[s] - comma-seperated list of files that will be used as index pages. Ant patterns can be used.


2 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,
])
like image 161
felipecrs Avatar answered Sep 27 '22 20:09

felipecrs


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.

like image 21
Sebien Avatar answered Sep 27 '22 22:09

Sebien