解决Jenkins中无法正常展示JMeter的HTML测试报告

1、当Jenkins是直接使用java启动的jenkins.war,则直接在启动命令中添加相关启动参数:

java -Dhudson.model.DirectoryBrowserSupport.CSP=  -jar jenkins.war

2、在Jenkins的Jenkins Script Console(系统管理→脚本命令)中运行以下命令:

  • Ps:这种方式在Jenkins重启后,会失效,需要重新执行一次。
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "")

3、如果是在Ubuntu环境下,通过apt-get install jenkins安装的Jenkins时:

vim /etc/init.d/jenkins

在do_start()的上一行添加以下内容(在第156行左右):

html="-Dhudson.model.DirectoryBrowserSupport.CSP= "

$SU -l $JENKINS_USER --shell=/bin/bash -c "$DAEMON $DAEMON_ARGS -- $JAVA后面添加$html,修改部分代码如下所示:

html="-Dhudson.model.DirectoryBrowserSupport.CSP= "
do_start()
{
    # the default location is /var/run/jenkins/jenkins.pid but the parent directory needs to be created
    mkdir `dirname $PIDFILE` > /dev/null 2>&1 || true
    chown $JENKINS_USER `dirname $PIDFILE`
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    $DAEMON $DAEMON_ARGS --running && return 1

    # Verify that the jenkins port is not already in use, winstone does not exit
    # even for BindException
    check_tcp_port "http" "$HTTP_PORT" "8866" "$HTTP_HOST" "0.0.0.0" || return 2

    # If the var MAXOPENFILES is enabled in /etc/default/jenkins then set the max open files to the
    # proper value
    if [ -n "$MAXOPENFILES" ]; then
        [ "$VERBOSE" != no ] && echo Setting up max open files limit to $MAXOPENFILES
        ulimit -n $MAXOPENFILES
    fi

    # notify of explicit umask
    if [ -n "$UMASK" ]; then
        [ "$VERBOSE" != no ] && echo Setting umask to $UMASK
    fi

    # --user in daemon doesn't prepare environment variables like HOME, USER, LOGNAME or USERNAME,
    # so we let su do so for us now
    $SU -l $JENKINS_USER --shell=/bin/bash -c "$DAEMON $DAEMON_ARGS -- $JAVA $html $JAVA_ARGS  -jar $JENKINS_WAR $JENKINS_ARGS" || return 2
}

修改完成并保存(ESC:wq!)后,执行以下命令

systemctl daemon-reload
systemctl restart jenkins.service

PS:最后需要清空浏览器缓存,重新打开Jenkins!

你可能感兴趣的:(Jenkins,Jmeter,jmeter,jenkins)