Sekar Karindra
Sekar Karindra

Reputation: 77

missing pie chart and other elements when display serenity report from jenkins

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?

Upvotes: 7

Views: 7318

Answers (5)

JRod
JRod

Reputation: 171

Since it is a Java property at the end, it could be setup either inside of the Jenkins application or at the Jenkins starting. In my case using Ubuntu, to add it needs to edit /usr/lib/systemd/system/jenkins.service and add the following line:

# Arguments for display Thucydes Reports correctly
Environment="JAVA_OPTS=-Dhudson.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';\""

Save the file and execute the following commands to finish the process:

sudo systemctl daemon-reload
sudo service jenkins restart

Now every time Jenkins is restarted the property is set !

Upvotes: 0

Usman Kokab
Usman Kokab

Reputation: 193

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';")

Upvotes: 4

vikramvi
vikramvi

Reputation: 3605

I got it working as below on Ubuntu 16.04

  1. 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:;\""

  2. Restart jenkins with command

    http://localhost:8080/safeRestart

  3. Goto Jenkins > Manage Jenkins > Script Console run below

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

  4. Close existing Jenkins browser window and open new one in incognito mode.

  5. References

    Jenkins Content Security Policy

    Jenkins - HTML Publisher Plugin - No CSS is displayed when report is viewed in Jenkins Server

Upvotes: 3

Alex Rewa
Alex Rewa

Reputation: 318

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) enter image description here

  • Enjoy results :-)

More details about content security policy: http://content-security-policy.com

Upvotes: 5

Sekar Karindra
Sekar Karindra

Reputation: 77

Solved. Need to downgrade Jenkins.

Upvotes: -2

Related Questions