【问题标题】:JMeter HTML Dashboard report not displaying in JenkinsJMeter HTML Dashboard 报告未在 Jenkins 中显示
【发布时间】:2019-06-27 01:34:16
【问题描述】:

我无法在 Jenkins 中查看 Jmeter Dashboard 报告,但是 jenkins 作业会创建一个 index.html 报告但它是空的

它在本地运行良好,并且 index.html 生成了所有必需的值。

我在这里错过了什么?

这是我的 pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.performance.dataengg</groupId>
  <artifactId>DataEngg</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <name>DataEngg</name>
  <url>http://maven.apache.org</url>

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <profiles>
        <profile>
            <id>Windows</id>
            <activation>
                <os>
                    <family>Windows</family>
                </os>
            </activation>
            <properties>
                <script.extension>.bat</script.extension>
            </properties>
        </profile>
        <profile>
            <id>unix</id>
            <activation>
                <os>
                    <family>unix</family>
                </os>
            </activation>
            <properties>
                <script.extension>.sh</script.extension>
            </properties>
        </profile>
    </profiles>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <filesets>
                        <fileset>
                            <directory>${basedir}/htmlReport/Reporting_framework/</directory>
                            <includes>
                                <include>AggregateReport.csv</include>
                                <include>Report.html</include>
                                <include>ReportOutput.zip</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin>

            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.7.0</version>
                <configuration>
                    <propertiesUser>
                        <threads>${threads}</threads>
                        <rampUp>${rampUp}</rampUp>
                        <baseURL>${baseURL}</baseURL>
                        <Pconstantthroughputtimer>${constantThroughputTimer}</Pconstantthroughputtimer>
                        <Resultsdirectory>${basedir}/target/jmeter/results/*.jtl</Resultsdirectory>
                        <loopCountDuration>${loopCountDuration}</loopCountDuration>

                    </propertiesUser>
                </configuration>
                <executions>
                    <!-- Run JMeter tests -->
                     <execution>
                        <id>jmeter-tests</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                </executions>
            </plugin>

             <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>pre-site</phase>
                        <configuration>
                            <tasks>
                                <delete dir="${basedir}/target/jmeter/results/dashboard" />
                                <mkdir dir="${basedir}/target/jmeter/results/dashboard" />
                                <copy file="${basedir}/src/test/resources/reportgenerator.properties"
                                         tofile="${basedir}/target/jmeter/bin/reportgenerator.properties" />
                                <copy todir="${basedir}/target/jmeter/bin/report-template">
                                    <fileset dir="${basedir}/src/test/resources/report-template" />
                                </copy>
                                <java jar="${basedir}/target/jmeter/bin/ApacheJMeter-4.0.jar" fork="true">
                                    <arg value="-l" />
                                    <arg value="${basedir}/target/jmeter/results/*.jtl" />
                                    <arg value="-g" />
                                    <arg value="${basedir}/target/jmeter/results/*.jtl" />
                                    <arg value="-o" />
                                    <arg value="${basedir}/target/jmeter/results/dashboard/" />
                                </java>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

会不会是一些 jenkins 配置出错了?

【问题讨论】:

    标签: jenkins jmeter report dashboard


    【解决方案1】:

    这要归功于 Jenkins Content Security Policy

    需要通过设置Java System Property来调整:

    hudson.model.DirectoryBrowserSupport.CSP

    由于它包含保留字符,您可以通过创建Groovy script 文件 $JENKINS_HOME/init.groovy 或目录 $JENKINS_HOME/init.groovy.d/ 中的任何 .groovy 文件来设置此属性,其中包含:

    System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "default-src 'self'; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline'; font-src *;img-src 'self' data: *;frame-ancestors 'self'")
    

    如果您希望了解更多关于性能测试和 JMeter 的信息,此book 可以为您提供帮助。

    请注意,您可以按照tutorial 轻松完成您正在做的事情。

    【讨论】:

    • jenkins 管理员说上述更改会带来安全风险,这是真的吗?如果是,那么替代解决方案是什么,我可以配置詹金斯工作本身的变化吗?
    • 它放松了安全性,但要求他解释风险。不,您不能在作业级别进行配置。没有其他解决方案AFAIK。如果答案是好的,请接受并投票。谢谢
    • 我尝试在配置节点级别使用脚本控制台来调整系统属性,但它对我不起作用。我在这里错过了什么?
    【解决方案2】:

    由于我的组织不允许放松安全性和重置内容安全策略,因此我使用docker 执行此操作,并且能够清晰地查看报告

    这里是 Dockerfile

    FROM alpine:3.9
    
    ENV JMETER_HOME /opt/apache-jmeter-5.1
    ENV JMETER_BIN ${JMETER_HOME}/bin
    ENV PATH $PATH:$JMETER_BIN
    ENV JMETER_DOWNLOAD_URL http://mirrors.estointernet.in/apache//jmeter/binaries/apache-jmeter-5.1.tgz
    
    RUN apk update \
        && apk upgrade \
        && apk add --update openjdk8-jre curl unzip bash \
        && rm -rf /var/cache/apk/* \
        && mkdir -p /tmp/dependencies  \
        && curl -L --silent ${JMETER_DOWNLOAD_URL} >  /tmp/dependencies/apache-jmeter-5.1.tgz  \
        && mkdir -p /opt  \
        && tar -xzf /tmp/dependencies/apache-jmeter-5.1.tgz -C /opt  \
        && rm -rf /tmp/dependencies
    
    COPY launch.sh /opt/
    COPY src/ /opt/src
    
    WORKDIR /opt
    
    ENTRYPOINT ["/opt/launch.sh"]
    

    您可以在launch.sh 中使用jmeter 命令,在src 文件夹中使用.jmx 脚本

    【讨论】:

      【解决方案3】:

      您可以使用HTML Publisher Plugin显示仪表板

      默认情况下Jenkins Content Security Policy 看起来像

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

      该值是从hudson.model.DirectoryBrowserSupport.CSP Java System property 读取的,因此您可以通过Jenkins Script Console 设置相关值(它将持续到下一次重新启动)或将相关参数添加到Jenkins 启动论点。

      您可能还对 Jenkins Performance Plugin 感兴趣,它添加了一些额外的功能,例如通过/失败标准和性能趋势图表

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多