2

I have a Java program that uses Selenium to test web sites. However when I run the program in Jenkins it generates a HTML report. When I open the report I get it with out CSS loaded.

To fix this I usually go to Jenkins->Script console and type in the following command:

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

(As described here: https://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy)

However after some time this rule is gone, so I need to put it into some config file.

My server is a Ubuntu 18.04 server. I have installed Jenkins under /var/lib/jenkins Here I have a file named config.xml, but I cant see any option on this hudson.model.DirectoryBrowserSupport.CSP.

Europa
  • 974
  • 12
  • 40
  • Does this answer your question? [Jenkins - HTML Publisher Plugin - No CSS is displayed when report is viewed in Jenkins Server](https://stackoverflow.com/questions/35783964/jenkins-html-publisher-plugin-no-css-is-displayed-when-report-is-viewed-in-j) – Jaap Jan 26 '23 at 14:15

1 Answers1

4

Create a Groovy script file $JENKINS_HOME/init.groovy, or any .groovy file in the directory $JENKINS_HOME/init.groovy.d/ with the following content:

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox allow-scripts; default-src 'self'; img-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline';")

systemctl restart jenkins

https://wiki.jenkins.io/display/JENKINS/Post-initialization+script

Karen Danielyan
  • 1,560
  • 1
  • 9
  • 13
  • 1
    Is there any alternative to this? My company doesn't allow us to change that and we are attaching the page to the build as a separate file but downloading the file for each build is tedious. – Cristian G Sep 03 '20 at 09:20