1.参考Jenkins+Ant+JMeter集成,安装Jenkins(不需要安装Performance Plugin插件),建立Slave节点,连接Slave节点,创建任务等。
2.将Jenkins+Ant+JMeter集成中创建的任务的第5步“构建后操作”删除,并将第1步修改(点击configure进行删除或修改)如下:
3.构建前,创建目录及所需文件:
目录1:
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New DocumentTITLE>
<META NAME&#61;"Generator" CONTENT&#61;"EditPlus">
<META NAME&#61;"Author" CONTENT&#61;"">
<META NAME&#61;"Keywords" CONTENT&#61;"">
<META NAME&#61;"Description" CONTENT&#61;"">
HEAD><BODY>
<table align&#61;"center"><tr align&#61;"center"><td><H1>Performance Test ReportH1>td>tr>
table><table align&#61;"center"><tr align&#61;"center"><td><H2>TPSH2>td>tr><tr align&#61;"center"><td><IMG SRC&#61;"TPS.png" WIDTH&#61;"800" HEIGHT&#61;"600" BORDER&#61;"0" ALT&#61;"">td>tr>
table><table align&#61;"center"><tr align&#61;"center"><td><H2>Response TimeH2>td>tr><tr align&#61;"center"><td><IMG SRC&#61;"ResponseTimeOverTime.png" WIDTH&#61;"800" HEIGHT&#61;"600" BORDER&#61;"0" ALT&#61;"">td>tr>
table>
BODY>
HTML>
xml version&#61;"1.0"?>
<project name&#61;"ant-jmeter" default&#61;"all"><description>Jmeter&#43;Ant&#43;Jenkins description><property name&#61;"jmeter.home" value&#61;"D:\software\apache-jmeter-5.1"/><property name&#61;"script.dir" value&#61;"D:\jmeterTest\script"/><property name&#61;"jmeter.result.dir" value&#61;"D:\jmeterTest\resultLog"/><property name&#61;"jmeter.jenkins" value&#61;"D:\jenkinsWorkshop\workspace\PerformanceTest"/><property name&#61;"report.title" value&#61;"Performance Test Summary Report"/><property name&#61;"jmeter.result.name" value&#61;"Test"/><property name&#61;"show-data" value&#61;"n"/><property name&#61;"format" value&#61;"2.1"/><condition property&#61;"style_version" value&#61;""><equals arg1&#61;"${format}" arg2&#61;"2.0"/>condition><condition property&#61;"style_version" value&#61;"_21"><equals arg1&#61;"${format}" arg2&#61;"2.1"/>condition><condition property&#61;"funcMode"><equals arg1&#61;"${show-data}" arg2&#61;"y"/>condition><condition property&#61;"funcMode" value&#61;"false"><not><equals arg1&#61;"${show-data}" arg2&#61;"y"/>not>condition><path id&#61;"jmeter.classpath"><fileset dir&#61;"${jmeter.home}\extras"><include name&#61;"ant-jmeter*.jar"/>fileset>path><taskdefname&#61;"jmeter"classpathref&#61;"jmeter.classpath"classname&#61;"org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/><target name&#61;"all" depends&#61;"run,generatePNG,report,copy-report"/><target name&#61;"generatePNG"><exec dir&#61;"D:\jmeterTest\" executable&#61;"cmd.exe"><arg line&#61;"/c D:\jmeterTest\generateRT.bat" /><arg line&#61;"/c exit" />exec><exec dir&#61;"D:\jmeterTest\" executable&#61;"cmd.exe"><arg line&#61;"/c D:\jmeterTest\generateTPS.bat" /><arg line&#61;"/c exit" />exec>target><target name&#61;"run"><echo>funcMode &#61; ${funcMode}echo><delete file&#61;"${jmeter.result.dir}/${jmeter.result.name}.html"/><delete file&#61;"${jmeter.result.dir}/${jmeter.result.name}.jtl"/><jmeterjmeterhome&#61;"${jmeter.home}"jmeterproperties&#61;"${jmeter.home}/bin/jmeter.properties"runremote&#61;"true"resultlog&#61;"${jmeter.result.dir}/${jmeter.result.name}.jtl"><testplans dir&#61;"${script.dir}" includes&#61;"*.jmx" /><property name&#61;"jmeter.save.saveservice.output_format" value&#61;"xml"/><property name&#61;"jmeter.save.saveservice.samplerData" value&#61;"true"/><property name&#61;"jmeter.save.saveservice.response_data.on_error" value&#61;"${funcMode}"/>jmeter>target><property name&#61;"lib.dir" value&#61;"${jmeter.home}/lib"/><path id&#61;"xslt.classpath"><fileset dir&#61;"${lib.dir}" includes&#61;"xalan*.jar"/><fileset dir&#61;"${lib.dir}" includes&#61;"serializer*.jar"/>path><target name&#61;"report" depends&#61;"xslt-report,copy-images"><echo>Report generated at ${report.datestamp}echo>target><target name&#61;"xslt-report" depends&#61;"_message_xalan"><tstamp><format property&#61;"report.datestamp" pattern&#61;"yyyy/MM/dd HH:mm"/>tstamp><xsltclasspathref&#61;"xslt.classpath"force&#61;"true" in&#61;"${jmeter.result.dir}/${jmeter.result.name}.jtl"out&#61;"${jmeter.result.dir}/${jmeter.result.name}.html"style&#61;"${jmeter.home}/extras/jmeter-results-detail-report${style_version}.xsl"><param name&#61;"showData" expression&#61;"${show-data}"/><param name&#61;"titleReport" expression&#61;"${report.title}"/><param name&#61;"dateReport" expression&#61;"${report.datestamp}"/>xslt>target><target name&#61;"copy-images" depends&#61;"verify-images" unless&#61;"samepath"><copy file&#61;"${jmeter.home}/extras/expand.png" tofile&#61;"${jmeter.result.dir}/expand.png"/><copy file&#61;"${jmeter.home}/extras/collapse.png" tofile&#61;"${jmeter.result.dir}/collapse.png"/>target><target name&#61;"verify-images"><condition property&#61;"samepath"><equals arg1&#61;"${jmeter.result.dir}" arg2&#61;"${jmeter.home}/extras/" />condition>target><tstamp><format property&#61;"CURRHOUR" pattern&#61;"yyyyMMddhhmm" offset&#61;"0" unit&#61;"hour" />tstamp><property name&#61;"RESULTNAME" value&#61;"${CURRHOUR}"/><target name&#61;"copy-report" depends&#61;"copy-images-jenkins"><mkdir dir&#61;"${jmeter.jenkins}\${RESULTNAME}" /><copy file&#61;"${jmeter.result.dir}/${jmeter.result.name}.html" tofile&#61;"${jmeter.jenkins}/${RESULTNAME}/${jmeter.result.name}.html"/><copy file&#61;"${jmeter.result.dir}/${jmeter.result.name}.jtl" tofile&#61;"${jmeter.jenkins}/${RESULTNAME}/${jmeter.result.name}.jtl"/><copy file&#61;"${jmeter.result.dir}/PerformanceTestReport.html" tofile&#61;"${jmeter.jenkins}/${RESULTNAME}/PerformanceTestReport.html"/>target><target name&#61;"copy-images-jenkins"><copydir dest&#61;"${jmeter.jenkins}/${RESULTNAME}" src&#61;"${jmeter.result.dir}"><include name&#61;"*.png" />copydir>target><condition property&#61;"xalan.present"><and><available classpathref&#61;"xslt.classpath" classname&#61;"org.apache.xalan.processor.TransformerFactoryImpl"/><available classpathref&#61;"xslt.classpath" classname&#61;"org.apache.xml.serializer.ExtendedContentHandler"/>and>condition><target name&#61;"_message_xalan" unless&#61;"xalan.present"><echo>Cannot find all xalan and/or serialiser jarsecho><echo>The XSLT formatting may not work correctly.echo><echo>Check you have xalan and serializer jars in ${lib.dir}echo>target><echo>jmeter.home &#61; ${jmeter.home}echo>
project>
rem TransactionsPerSecond
D:\software\apache-jmeter-5.1\bin\PluginsManagerCMD.bat --tool Reporter --generate-png D:\jmeterTest\resultLog\TPS.png --input-jtl D:\jmeterTest\resultLog\Test.jtl --plugin-type TransactionsPerSecond --width 800 --height 600
%ANT_HOME%\bin\ant -f D:\jmeterTest\build.xml
rem ResponseTime OverTime
D:\software\apache-jmeter-5.1\bin\PluginsManagerCMD.bat --tool Reporter --generate-png D:\jmeterTest\resultLog\ResponseTimeOverTime.png --input-jtl D:\jmeterTest\resultLog\Test.jtl --plugin-type ResponseTimesOverTime --width 800 --height 600
注意&#xff1a;可以仿照上面的generateTPS.bat生成其它的所需报表&#xff0c;具体用法见&#xff1a;https://jmeter-plugins.org/wiki/JMeterPluginsCMD/
目录2&#xff1a;
4.修改jmeter.properties文件&#xff0c;使之可以远程启动&#xff1a;
# Remote Hosts - comma delimited
remote_hosts&#61;127.0.0.1
#remote_hosts&#61;localhost:1099,localhost:2010
5.双击启动jmeter-server.bat&#xff0c;如果报错如下&#xff1a;
Found ApacheJMeter_core.jar
Server failed to start: java.rmi.server.ExportException: Listen failed on port:
0; nested exception is:
java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)An error occurred: Listen failed on port: 0; nested exception is:
java.io.FileNotFoundException: rmi_keystore.jks (系统找不到指定的文件。)errorlevel&#61;1
请按任意键继续. . .
则修改jmeter.properties文件即可&#xff1a;
# Set this if you don&#39;t want to use SSL for RMI
server.rmi.ssl.disable&#61;true
6.点击“立即构建”。构建成功后两个目录如下&#xff1a;
目录1&#xff1a;
目录2&#xff1a;
7. 在Jenkins工作目录中打开PerformanceTestReport.html即可查看报表。