Resolving CSS Display Issues in Jenkins HTML Publisher Plugin

Dec 03, 2025 · Programming · 10 views · 7.8

Keywords: html | css | jenkins | jenkins-plugins | content-security-policy

Abstract: This article addresses the problem where CSS styles are not displayed in HTML reports when viewed on the Jenkins server using the HTML Publisher Plugin. The core cause is Jenkins' default Content Security Policy (CSP), which restricts inline and external CSS. The solution involves modifying system properties via the Script Console to disable CSP, with discussions on security risks and best practices. Aimed at Jenkins administrators and developers for quick diagnosis and fix.

Problem Description

When using the HTML Publisher Plugin in Jenkins, users often encounter an issue where CSS styles are stripped from HTML reports when viewed on the Jenkins server, resulting in unformatted pages. However, downloading the same reports locally displays CSS correctly. This inconsistency affects report readability and functionality, requiring a solution.

Root Cause: Content Security Policy (CSP)

The root of this problem lies in Jenkins' default Content Security Policy (CSP). CSP is a security mechanism designed to prevent threats like cross-site scripting (XSS) by restricting the types of resources a page can load. Jenkins' default CSP rule is: sandbox; default-src 'none'; img-src 'self'; style-src 'self';. This rule entails:

Thus, when HTML reports include inline or external CSS, CSP prevents their loading, causing style loss. This explains why local viewing works (no CSP restrictions) but server-side viewing fails.

Solution: Modifying CSP Settings

To resolve CSS display issues, CSP restrictions need to be relaxed. The most direct approach is to disable CSP, but this may introduce security risks and is recommended only for testing or controlled environments. Follow these steps:

  1. Log into the Jenkins management interface and navigate to Manage Jenkins.
  2. Select Manage Nodes.
  3. Click the settings icon (gear icon).
  4. In the left menu, click Script Console.
  5. In the script console, enter the following command and click Run:
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

After execution, if the output shows "Result:" (under the "Result" header), CSP protection is disabled. Then, re-run the build job, and newly archived HTML files should display CSS styles normally. This method overrides the default CSP rule by setting a system property, allowing CSS loading.

Considerations and Best Practices

Disabling CSP can expose Jenkins instances to security threats, such as XSS attacks. Therefore, it is advised to:

By balancing functionality and security, HTML reports can be displayed both aesthetically and safely in Jenkins.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.