ant构建文件build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
<tstamp>
<format property="time" pattern="yyyyMMddHHmm" />
</tstamp>
<!-- 本地存放报告的路径-->
<property name="basedirectory" value="D:\reports" />
<!-- 本地存放脚本的路径-->
<property name="scriptdirectory" value="D:\apache-jmeter-5.2.1\loadTest" />
<!-- 需要改成自己本地的 Jmeter 目录-->
<property name="jmeter.home" value="D:\apache-jmeter-5.2.1" />
<!-- jmeter生成jtl格式的结果报告的路径-->
<property name="jmeter.result.jtl.dir" value="${basedirectory}" />
<!-- jmeter生成html格式的结果报告的路径-->
<property name="jmeter.result.html.dir" value="${basedirectory}" />
<!-- Name of test (without .jmx) -->
<property name="test" value="YTtest"/>
<!-- 生成的报告的前缀 htmlm名称与jenkins,HTML directory to archive 设置一致,否则报告会出现404-->
<property name="ReportName" value="TestReport" />
<property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${test}${time}.jtl" />
<property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/YT_API自动化测试报告${time}.html" />
<path id="xslt.classpath">
<fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/>
<fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/>
</path>
<target name="run">
<antcall target="test" />
<antcall target="report" />
</target>
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
<!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本${test}-->
<testplans dir="${scriptdirectory}" includes="*.jmx" />
</jmeter>
</target>
<target name="report">
<tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" /></tstamp>
<xslt classpathref="xslt.classpath"
force="true"
in="${jmeter.result.jtlName}"
out="${jmeter.result.htmlName}"
style="${basedirectory}/jmeter.results.shanhe.me.xsl"> <!-- 选用的报告样式脚本名称要一致-->
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
<copy todir="${jmeter.result.html.dir}">
<fileset dir="${jmeter.home}/extras">
<include name="collapse.png" />
<include name="expand.png" />
</fileset>
</copy>
</target>
</project>