问题
Need your help!
I've been working on integrating my automation test to Jenkins. I use Serenity BDD and JBehave. My Serenity report displayed OK when I run my test manually. But, when I integrate the test to Jenkins and try to display the report through Publish HTML Report Plugin, it can't display the pie chart and missing other elements as well.
Any idea how to solve this?
回答1:
Actually you don't need to downgrade Jenkins. This issue happens because of new content security policy headers that is supported by modern browsers. Correct resolution could be the following (code examples and paths for CentOS 7):
Configure content policy headers via Jenkins system property:
sudo vim /etc/sysconfig/jenkins set java options as following: JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"sandbox allow-forms allow-scripts; default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline';\"" # save and exit sudo /etc/init.d/jenkins restart
Install Jenkins CORS Filter Plugin: https://wiki.jenkins-ci.org/display/JENKINS/Cors+Filter+Plugin
Setup CORS (Manage Jenkins -> Configure System -> CORS Filter)
Enjoy results :-)
More details about content security policy: http://content-security-policy.com
回答2:
I got it working as below on Ubuntu 16.04
Goto /etc/default/jenkins and set below value
JAVA_ARGS="-Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"sandbox allow-forms allow-scripts; default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src data:;\""
Restart jenkins with command
http://localhost:8080/safeRestart
Goto Jenkins > Manage Jenkins > Script Console run below
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
Close existing Jenkins browser window and open new one in incognito mode.
References
Jenkins Content Security Policy
Jenkins - HTML Publisher Plugin - No CSS is displayed when report is viewed in Jenkins Server
回答3:
I have been also facing the same problem. I used some code in the script console to show Extent Report via HTML plugin, it worked but the pie chart was not visible, then after exploring a lot, finally I also found the following code by which I am also able to view the pie chart in my extent reports. Go into Script Console and run the following code;
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "default-src * 'unsafe-inline' 'unsafe-eval'; script-src * 'unsafe-inline' 'unsafe-eval'; connect-src * 'unsafe-inline'; img-src * data: blob: 'unsafe-inline'; frame-src *; style-src * 'unsafe-inline';")
回答4:
Solved. Need to downgrade Jenkins.
来源:https://stackoverflow.com/questions/34740963/missing-pie-chart-and-other-elements-when-display-serenity-report-from-jenkins