Programing

Jenkins-HTML 게시자 플러그인-Jenkins 서버에서 보고서를 볼 때 CSS가 표시되지 않음

crosscheck 2020. 11. 10. 07:50
반응형

Jenkins-HTML 게시자 플러그인-Jenkins 서버에서 보고서를 볼 때 CSS가 표시되지 않음


Jenkins HTML Publisher 플러그인에 이상한 문제가 있습니다. 여기서 보고서에 추가 한 모든 멋진 CSS는 Jenkins에서 볼 때 제거됩니다. 보고서를 로컬로 다운로드하면 CSS 형식을 볼 수 있습니다. Jenkins에 CSS를 볼 수있는 설정이 있습니까?

Jenkins의 내 HTML 게시자 설정 :

여기에 이미지 설명 입력

Jenkins에 표시 될 때 내 보고서 페이지 :

여기에 이미지 설명 입력

로컬에 표시 될 때 내 보고서 페이지 :

여기에 이미지 설명 입력


문제를 파악했습니다. 다른 사용자를 위해 여기에서 공유합니다.

Jenkins의 콘텐츠 보안 정책으로 인해 CSS가 제거되었습니다. ( https://wiki.jenkins-ci.org/display/JENKINS/Configuring+Content+Security+Policy )

기본 규칙은 다음과 같이 설정됩니다.

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

이 규칙 세트의 결과는 다음과 같습니다.

  • 자바 스크립트가 전혀 허용되지 않음
  • 플러그인 (객체 / 포함)이 허용되지 않음
  • 인라인 CSS 또는 다른 사이트의 CSS는 허용되지 않습니다.
  • 다른 사이트의 이미지는 허용되지 않습니다.
  • 허용되는 프레임 없음
  • 허용되는 웹 글꼴 없음
  • XHR / AJAX는 허용되지 않습니다.

이 규칙을 완화하려면 다음으로 이동하십시오.

  1. Jenkins 관리->
  2. 노드 관리->
  3. 설정 (톱니 바퀴 아이콘)-> 클릭
  4. 왼쪽의 스크립트 콘솔을 클릭하고 다음 명령을 입력하십시오.

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

그리고 실행을 누릅니다. 출력이 "결과"헤더 아래에 '결과 :'로 표시되면 보호가 비활성화 된 것입니다. 빌드를 다시 실행하면 보관 된 새 HTML 파일에 CSS가 활성화되어 있음을 알 수 있습니다.


에서 가상 코어 , HTML 보고서에 이미지를 사용하려면

  • sudo vi /etc/sysconfig/jenkins
  • 다음으로 설정 JENKINS_JAVA_OPTION

JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' 'unsafe-inline' data:;\""

젠킨스 서버를 다시 시작한 후에도 작동합니다.


지령

default-src: The default-src is the default policy for loading content such as JavaScript, Images, CSS, Fonts, AJAX requests, Frames, HTML5 Media

img-src: Defines valid sources of images.

Source Value

' self ' - Allows loading resources from the same origin (same scheme, host and port).

Usage : default-src 'self'

' unsafe-inline ' - Allows use of inline source elements such as style attribute, onclick, or script tag bodies (depends on the context of the source it is applied to) and javascript: URIs.

Usage : default-src 'unsafe-inline'

' unsafe-eval ' - Allows unsafe dynamic code evaluation such as JavaScript eval()

Usage : default-src 'unsafe-eval'

data: - Allows loading resources via the data scheme (eg Base64 encoded images).

Usage : img-src 'self' data:

Please refer more about content security policy here


Go to “Manage Jenkins” -> “Script console” and run below command:

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

(The following solution is for Windows.)

A permanent fix is to change a line in [Jenkins directory]\jenkins.xml (for me it's at C:\Jenkins\jenkins.xml)

<executable>java.exe</executable>
<arguments>[arguments are here]</arguments>

Add the following argument to the whitespace-separated list of arguments:

-Dhudson.model.DirectoryBrowserSupport.CSP=

Then restart the Jenkins service to pick up the change.


You can fix this by using the groovy command as specified in Vall's answer.

The effect is in place until Jenkins restarts and afterwards you have to do it again.

A solution to solve this problem is to configure a job that will do this for you whenever jenkins starts up.

You can do this by using the Startup Trigger plugin.

After you install it create a new job and you will have a new checkbox under the Build Triggers section that you will have to check.

Then add an Execute system Groovy script build step with the command:

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

Save and everything should work.


For Ubuntu 14 version helpful was special plugins:

https://wiki.jenkins-ci.org/display/JENKINS/Startup+Trigger - To start job on jenkins startup

https://wiki.jenkins-ci.org/display/JENKINS/Groovy+plugin - To run System Groovy script

And I made a job, that starts on Jenkins restart and sets parametr.

Jenkins가 실행 된 후 빌드를 시작하도록 설정

And added system Groovy script to set parametr. 시스템 Groovy 스크립트 실행 System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox; img-src 'self';")


Go To

Manage Jenkins --> Script console

and type in the following command:

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

then Press Run. if you get the output as 'Result', then rerun the build check the HTML report format


It's too late to respond but thought to share.

I was struggling with Jenkins deployed on Tomcat, tried execution of script, it helps but goes away if tomcat is rebooted.

Made the permanent fix by setting the property in catalina.properties in tomcat.

Properties file: tomcat_installation_dir/conf/catalina.properties Just copy paste the below line in catalina.properties at the last (you can set it anywhere just to not mess with existing properties)

-Dhudson.model.DirectoryBrowserSupport.CSP=""


I had the same issues after adding HTTPS to my jenkins. In case you are having the same issue, the solution is easy - set your Jenkins url to use HTTPS protocol instead of HTTP. It can be configured via jenkins configuration -> jenkins url


For setting permanently 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


To set the system property permanently if using Jenkins-X, then create the file myvalues.yaml in the current directory, with the following content:

jenkins:
  Master:
    JavaOpts: >
      -Dhudson.model.DirectoryBrowserSupport.CSP=

Then restart the jenkins-x platform, which can be done by upgrading it:

$ jx upgrade platform --always-upgrade
# Presumably jx.exe is used if on Windows (not tested)

실제로 플랫폼을 업그레이드하지 않으려면 동일한 버전으로 강제로 업그레이드하십시오.

$ version=$(jx version --no-version-check\
            | grep 'jenkins x platform' | sed -e 's/^jenkins.\+ //')
$ jx upgrade platform --version ${version} --always-upgrade

데비안 / 우분투 에서 적성 설치 :

  • sudo vi /etc/default/jenkins
  • 추가 -Dhudson.model.DirectoryBrowserSupport.CSP=받는 사람 JAVA_ARGS(예를 들어 JAVA_ARGS="-Dhudson.model.DirectoryBrowserSupport.CSP=")
  • Jenkins 다시 시작- service jenkins restart

이것은 나에게 충분했지만 매개 변수의 전체 목록은 this answer를 참조하십시오 .

참고 URL : https://stackoverflow.com/questions/35783964/jenkins-html-publisher-plugin-no-css-is-displayed-when-report-is-viewed-in-j

반응형