Learn › Jenkins

Jenkins Reports and Artifacts: Publish HTML, CSV and Build History

Turn Jenkins pipeline output into useful reports: archive CSV and HTML artifacts, publish HTML reports, keep build history and fail on bad results.

Advanced 10 min read
By Gopinath Karthikeyan

A pipeline that prints 2,000 lines of console output is technically a report – nobody will read it. A one-page HTML summary with a red/green status per server will be read every time. This guide shows how to produce and publish both.

Produce data, then format it

Have your script write structured output first (CSV or JSON), then build HTML from it. The CSV feeds other tools; the HTML is for people.

# scripts/Get-ServiceReport.ps1 (runs on a Windows agent)
$servers = Get-Content $env:SERVER_FILE
$rows = foreach ($s in $servers) {
    try {
        $svc = Invoke-Command -ComputerName $s -ScriptBlock { Get-Service W3SVC } -ErrorAction Stop
        [pscustomobject]@{ Server = $s; Status = [string]$svc.Status; Result = if ($svc.Status -eq 'Running') {'OK'} else {'FAIL'} }
    } catch {
        [pscustomobject]@{ Server = $s; Status = 'Unreachable'; Result = 'FAIL' }
    }
}
New-Item -ItemType Directory reports -Force | Out-Null
$rows | Export-Csv reports\services.csv -NoTypeInformation
$rows | ConvertTo-Html -Title 'Service report' -CssUri 'report.css' -PreContent "<h1>W3SVC status</h1><p>$(Get-Date)</p>" |
    Out-File reports\index.html -Encoding utf8
Copy-Item report.css reports\
if ($rows.Result -contains 'FAIL') { exit 1 }

Archive artifacts

post {
    always {
        archiveArtifacts artifacts: 'reports/**', allowEmptyArchive: true, fingerprint: true
    }
}

always matters: you want the report most when the build failed. Artifacts appear on the build page for download.

Publish HTML inside Jenkins

With the HTML Publisher plugin:

publishHTML(target: [
    reportDir: 'reports',
    reportFiles: 'index.html',
    reportName: 'Service report',
    keepAll: true,
    alwaysLinkToLastBuild: true,
    allowMissing: true
])

A Service report link appears on the job and build pages.

Why does my report look unstyled?

Jenkins serves archived files with a strict Content Security Policy, which blocks inline <style> blocks and JavaScript. Use an external CSS file next to the HTML (-CssUri report.css above) and avoid scripts. Don’t weaken the CSP globally to make a report pretty – it protects Jenkins from malicious content in build output.

Keep the right amount of history

options {
    buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '10'))
}

Keep build logs long enough for audits, but artifacts for fewer builds – they use the most disk. If you need longer retention, copy reports to a file share or object storage as a final step.

Fail, warn or pass – on purpose

Decide what the report’s result means for the build:

  • Exit 1 from the script → build FAILED (red) – something must be fixed.
  • unstable('2 servers need attention') → build UNSTABLE (yellow) – worth a look, not an emergency.
  • Exit 0 → SUCCESS (green).
script {
    def fails = readFile('reports/services.csv').readLines().count { it.contains('"FAIL"') }
    if (fails > 0 && fails < 3) { unstable("${fails} server(s) failed the check") }
}

(readFile reads from the workspace; this runs before the always archive step.)

Send the build URL plus the report link in your chat or email notification. People click a one-line message; they ignore a wall of text.

FAQ

Can I see trends across builds? For test-style results, publish them as JUnit XML (junit 'reports/*.xml') and Jenkins draws a trend graph. Pester can write that format directly.

What’s next

You’ve completed the Jenkins track. Continue with Ansible inventories and variables.

Practise this topic

Test yourself with free questions on this topic – instant answers and explanations.

Start practice questions

JenkinsReportingArtifactsHTMLAdvanced

Gopinath Karthikeyan

Gopinath Karthikeyan – Windows Site Reliability Engineer with about 12 years in enterprise Windows Server infrastructure, and founder of WinOps Academy. YouTube · LinkedIn

More in Jenkins