- 一、环境准备
1、JDK环境:http://www.oracle.com/technetwork/java/javase/downloads/index.html
2、ANT环境:http://ant.apache.org/bindownload.cgi
3、Jmeter:http://jmeter.apache.org/download_jmeter.cgi
4、将 jmeter的extras目录中ant-jmeter-1.1.1.jar包拷贝至ant安装目录下的lib目录中
5、修改Jmeter的bin目录下jmeter.properties文件的配置:jmeter.save.saveservice.output_format=xml
6、配置JDK和ANT的环境变量
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export ANDROID_HOME=/Users/chichi/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export ANT_HOME=/Applications/apache-ant-1.9.7
export PATH=${PATH}:${ANT_HOME}/bin
7、ant的build.xml文件
<?xml version="1.0" encoding="utf-8"?> <project name="JmeterTest" default="all" basedir="."> <tstamp> <format property="time" pattern="yyyyMMddhhmm" /> </tstamp> <!-- 需要改成自己本地的 Jmeter 目录--> <property name="jmeter.home" value="/Applications/apache-jmeter-3.0" /> <!-- jmeter生成jtl格式的结果报告的路径--> <property name="jmeter.result.jtl.dir" value="report/jtl" /> <!-- jmeter生成html格式的结果报告的路径--> <property name="jmeter.result.html.dir" value="report/html" /> <!-- 生成的报告的前缀 --> <property name="ReportName" value="TestReport" /> <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" /> <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" /> <!-- 接收测试报告的邮箱 --> <property name="mail_to" value="chengqian@souche.com" /> <!-- 电脑地址 --> <property name="ComputerName" value="chichi" /> <target name="all"> <antcall target="login" /> <antcall target="report" /> </target> <target name="login"> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" /> <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本 --> <testplans dir="/Applications/apache-ant-1.9.7/" includes="11.jmx" /> <property name="jmeter.save.saveservice.output_format" value="xml" /> </jmeter> </target> <target name="report"> <xslt in="${jmeter.result.jtlName}" out="${jmeter.result.htmlName}" style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" /> <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 --> <copy todir="${jmeter.result.html.dir}"> <fileset dir="${jmeter.home}/extras"> <include name="collapse.png" /> <include name="expand.png" /> </fileset> </copy> </target> <!-- 发送邮件 --> </project>
- 二、jenkins新建项目
1.jenkins安装ant插件
2.ant插件全局配置
---------------------------------------------------------------------------------------------------------------------
3.新建一个项目,配置如下:
4、立即构建,构建成功,如下:
---------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------