JMeter HTML Dashboard报告未显示在Jenkins中

问题描述 投票:2回答:3

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

jenkins

它在本地工作正常,并生成index.html所有必需的值。

local

我在这里错过了什么?

这是我的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
3个回答
2
投票

这是由于Jenkins Content Security Policy

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

hudson.model.DirectoryBrowserSupport.CSP

由于它包含保留字符,您可以通过在$ JENKINS_HOME / init.groovy.d /目录中创建Groovy script文件$ JENKINS_HOME / init.groovy或任何.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轻松完成您正在做的事情。


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"]

你可以在jmeter文件夹里面的launch.sh和.jmx脚本中找到你的src命令


0
投票

您可以使用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感兴趣,它增加了一些额外的功能,如通过/失败标准和性能趋势图表

© www.soinside.com 2019 - 2024. All rights reserved.