Reputation: 375
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
Reputation: 712
As Sebien's answer but:
script
blockpublishHTML([
reportName: 'Newman Report'
reportDir: 'reports',
reportFiles: "${dir('reports') { findFiles(glob: '**/*.html').join(',') ?: 'Not found' }}",
allowMissing: true,
alwaysLinkToLastBuild: true,
keepAll: true,
])
Upvotes: 3
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
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'
] )
Upvotes: 2
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
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
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