Jenkins reports in HTML Optimization

Jenkins deploying continuous integration process often used HTML Publisher Plugin plugin to display the test report.

For aesthetic style and readability test report, test report, often with CSS and JS implement custom style or animation.

Jenkins when they access a self-test reports or custom style animation, showing the style often beyond your imagination, beyond recognition, style confusion, unable to display animations and so on. Open your browser and development tool console, you can see CSS, JS failed to load.

 

 

Cause Analysis

Jenkins To avoid malicious HTML / JS files, the default security policy CSP is set to:

sandbox; default-src 'none'; img-src 'self'; style-src 'self';

In this configuration, only allowed to load:

1, CSS files hosted on the server Jenkins

2, Jenkins hosted on the server image files

The following forms of content will be prohibited:

  • Java
  • plugins (object/embed)
  • Inline HTML style sheet (Inline style sheets), and references to external CSS files station
  • Inline HTML image (Inline image definitions), as well as image files referenced outstation
  • frames
  • web fonts
  • XHR / AJAX

Solution

Method one: Modify the CSP (Content Security Policy) default configuration, system management to Jenkins à script command line, execute the following command Groovy, and then click Run. Once configured, re-build the original project, HTML pages to display properly.

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", ""

 

 

 

 

However, when you restart jenkins, you will find, HTML pages beyond recognition again, CSP revert to the default configuration, so this approach is only a temporary solution.

Method 2: Using the Groovy plugin jenkins permanent solution to this problem

1, Groovy plugin: Groovy code may direct execution.

Resolve as follows:

In the "build" module, select the "Execute system Groovy script", run the following command Groovy:

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

 

 Method three: the linux environment, if jenkins through tomcat container when activated, may be performed by setting the parameters, vi / etc / profile

export JAVA_OPTS="-Dhudson.model.DirectoryBrowserSupport.CSP="sandbox; default-src 'self';""

Execution: source / etc / profile

Restart jenkins

Method four: When the project configuration, adding post-build operation: Grooy script, execute the command: System.setProperty ( "hudson.model.DirectoryBrowserSupport.CSP", "")

 

 

Guess you like

Origin www.cnblogs.com/jassa/p/12585800.html