Jenkins+ant+jmeter接口自动化
1.Jenkins新建slave节点
2.Jenkins新建job,配置job,关联到slave,
3.执行构建
build文件如下
<?xml version="1.0" encoding="UTF8"?> <project name="ant-jmeter-test" default="all" basedir="."> <tstamp> <format property="time" pattern="yyyyMMddhhmm" /> </tstamp> <property environment="env"/> <property name="ReportName" value="TestReport" /> <!--jmeter目录--> <property name="jmeter.home" value="D:\Program Files\apache-jmeter-3.0" /> <property name="jmeter.result.dir" value="${env.WORKSPACE}/results/${env.BUILD_ID}" /> <!--报告前缀--> <property name="ReportName" value="TestReport" /> <property name="jmeter.result.jtlName" value="${jmeter.result.dir}/${ReportName}${time}.jtl" /> <property name="jmeter.result.htmlName" value="${jmeter.result.dir}/${ReportName}${time}.html" /> <target name="all"> <echo message="start..."/> <antcall target="clean" /> <antcall target="test" /> <antcall target="report" /> </target> <target name="clean"> <mkdir dir="${env.WORKSPACE}/results/${env.BUILD_ID}" /> </target> <target name="test"> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" /> <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> <!--需要运行的jmeter脚本--> <testplans dir="D:\Program Files\apache-jmeter-3.0\demo" includes="*.jmx" /> <property name="jmeter.save.saveservice.output_format" value="xml"/> </jmeter> </target> <path id="xslt.classpath"> <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/> <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/> </path> <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="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl" > <param name="dateReport" expression="${report.datestamp}"/> </xslt> <copy todir="${jmeter.result.dir}"> <fileset dir="${jmeter.home}/extras"> <include name="collapse.png" /> <include name="expand.png" /> </fileset> </copy> </target> </project>