JMeter HTML 仪表板报告未在 Jenkins 中显示
JMeter HTML Dashboard report not displaying in Jenkins
我无法在 Jenkins 中查看 Jmeter 仪表板报告,但是 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 Content Security Policy。
需要通过设置Java系统属性进行调整:
hudson.model.DirectoryBrowserSupport.CSP
因为它包含保留字符,您可以通过创建 Groovy script 文件 $JENKINS_HOME/init.groovy 或任何 .groovy 来设置它 属性目录 $JENKINS_HOME/init.groovy.d/ 中的文件包含:
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.
轻松完成您正在做的事情
您可以使用 HTML Publisher Plugin
显示仪表板
默认情况下 Jenkins Content Security Policy 看起来像
sandbox; default-src 'none'; img-src 'self'; style-src 'self';
正在从 hudson.model.DirectoryBrowserSupport.CSP
Java System property so you can configure it to more "relaxed" by setting the relevant value via Jenkins Script Console 中读取值(它将一直存在到下一次重启)或通过将相关参数添加到 Jenkins 启动参数。
您可能还对 Jenkins Performance Plugin 感兴趣,它添加了一些额外的功能,例如 pass/fail 标准和绩效趋势图表
由于我的组织不允许放松安全措施和重置内容安全策略,因此我使用 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 脚本
我无法在 Jenkins 中查看 Jmeter 仪表板报告,但是 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 Content Security Policy。
需要通过设置Java系统属性进行调整:
hudson.model.DirectoryBrowserSupport.CSP
因为它包含保留字符,您可以通过创建 Groovy script 文件 $JENKINS_HOME/init.groovy 或任何 .groovy 来设置它 属性目录 $JENKINS_HOME/init.groovy.d/ 中的文件包含:
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.
轻松完成您正在做的事情您可以使用 HTML Publisher Plugin
显示仪表板默认情况下 Jenkins Content Security Policy 看起来像
sandbox; default-src 'none'; img-src 'self'; style-src 'self';
正在从 hudson.model.DirectoryBrowserSupport.CSP
Java System property so you can configure it to more "relaxed" by setting the relevant value via Jenkins Script Console 中读取值(它将一直存在到下一次重启)或通过将相关参数添加到 Jenkins 启动参数。
您可能还对 Jenkins Performance Plugin 感兴趣,它添加了一些额外的功能,例如 pass/fail 标准和绩效趋势图表
由于我的组织不允许放松安全措施和重置内容安全策略,因此我使用 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 脚本