4

I am using Testcafe for my project tests and I am generating a HTML report with screenshot and video in my project.

When I am trying to publish the report using HTML publisher, the video is not playing. When I open the generated HTML file in the Jenkins agent via browser, the video is playing fine. not sure, why it is not playing on the Jenkins HTML publisher plugin.

MY HTML video code looks like below

<div class="row">
   <div class="column">
      <img id="myImg" class="errImage" src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAABAAAA" style="width:100%;">  
   </div>
   <div class="column">
      <video autoplay muted loop controls id="errorVideo" style="width:99%">
         <source src="C:\Program Files (x86)\Jenkins\workspace\Free style node test\e2e\artifacts\videos\Getting Started\My First Test\1.mp4" type="video/mp4">
      </video>
   </div>
</div>

I tried configuring following content security policy

System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox; default-src '';")

not sure what policy is blocking the video from playing on the Jenkins publisher.

Can someone help to resolve this issue? Thanks in advance.

  • did you try to use url path related to jenkins fqdn + build artifact ? example: http://localhost/Free%20style%20node%20test/e2e/artifacts/videos/Getting%20Started/My%20First%20Test/1.mp4 – Infern0 Apr 30 '20 at 06:32
  • yes, I tried that one as well still no use :( –  Apr 30 '20 at 14:41
  • 1
    Try setting CSP as illustrated in this thread: [Allow All Content Security Policy?](https://stackoverflow.com/questions/35978863/allow-all-content-security-policy). – Alex Skorkin May 01 '20 at 13:01

1 Answers1

3

The policy which blocking your video from playing is media-src == "none", derived from default-src == 'none' (see https://wiki.jenkins.io/display/JENKINS/Configuring+Content+Security+Policy)

Take a look at the solution in https://github.com/jenkinsci/screenrecorder-plugin/blob/master/src/main/java/org/jenkinsci/plugins/screenrecorder/ScreenRecorderBuildWrapper.java, it could work for you:

String curCsp = System.getProperty("hudson.model.DirectoryBrowserSupport.CSP","");
if (!curCsp.contains("media-src"))
{
       System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", curCsp + ";media-src 'self';");
}
  • I executed your script through script console, still, the video is not getting displayed through HTML Publisher plugin. –  Jun 22 '20 at 02:00
  • What is the return value of System.getProperty("hudson.model.DirectoryBrowserSupport.CSP","") after your script execution? – Dimitri Tenenbaum Jun 22 '20 at 11:59
  • I ran this `String curCsp = System.getProperty("hudson.model.DirectoryBrowserSupport.CSP",""); println(curCsp)` I got result as `;media-src 'self';` –  Jun 22 '20 at 14:45
  • Maybe the execution in the script console doesn't have any impact on global properties? Tyr to this parameter to empty string in your jenkins start script, example: -Dhudson.model.DirectoryBrowserSupport.CSP= -DJENKINS_HOME=... – Dimitri Tenenbaum Jun 23 '20 at 14:27