Win下Jenkins+Jmeter+Ant自动化集成环境搭建
环境:win10
涉及:Jdk1.7.0_80、Jenkins2.60.3、Jmeter3.1、Ant1.9.9
步骤:
1. Java下载、安装、配置环境变量、验证
l 安装:默认
l 配置:JAVA_HOME:C:\Program Files\Java\jdk1.7.0_80
l 配置:Path:增加%JAVA_HOME%\bin;
l 验证:win+R输入cmd进入cmd.exe,执行javac -version,显示java版本即表示jdk安装成功
2. Jmeter下载、安装、配置环境变量、验证
l 下载:http://archive.apache.org/dist/jmeter/binaries/
l 解压:默认
l 配置:JMETER_HOME:D:\01Test\02Jmeter\apache-jmeter-3.1
l 配置:
CLASSPATH:%JMETER_HOME%\lib\ext\ApacheJMeter_core.jar;%JMETER_HOME%\lib\jorphan.jar;%JMETER_HOME%\lib\logkit-2.0.jar;
l 启动:进入\apache-jmeter-3.1\bin下启动jmeter.bat,jmeter启动成功即为安装成功
3. Ant下载、配置环境变量、验证
l 下载:http://ant.apache.org/bindownload.cgi
l 解压:默认
l 配置:ANT_HOME:D:\01Test\02Jmeter\ant
l 配置:CLASSPATH:增加%ANT_HOME%\lib;
l 配置:Path:增加%ANT_HOME%\bin;
l 验证:win+R输入cmd进入cmd.exe,进入ant目录,执行ant -version,显示版本即表示安装成功
4. 修改jmeter.properties
修改apache-jmeter3.1\bin下的jmeter.properties
# assertion_results_failure_message only affects CSV output
jmeter.save.saveservice.assertion_results_failure_message=true
#
# legitimate values: none, first, all
#jmeter.save.saveservice.assertion_results=none
#
jmeter.save.saveservice.data_type=true
jmeter.save.saveservice.label=true
jmeter.save.saveservice.response_code=true
#response_data is not currently supported for CSV output
jmeter.save.saveservice.response_data=true
#Save ResponseData for failed samples
jmeter.save.saveservice.response_data.on_error=false
jmeter.save.saveservice.response_message=true
jmeter.save.saveservice.successful=true
jmeter.save.saveservice.thread_name=true
jmeter.save.saveservice.time=true
jmeter.save.saveservice.subresults=true
#jmeter.save.saveservice.assertions=true
jmeter.save.saveservice.latency=true
jmeter.save.saveservice.connect_time=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.responseHeaders=false
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.encoding=false
jmeter.save.saveservice.bytes=true
# Only available with HttpClient4
jmeter.save.saveservice.sent_bytes=true
jmeter.save.saveservice.url=false
jmeter.save.saveservice.filename=false
jmeter.save.saveservice.hostname=true
jmeter.save.saveservice.thread_counts=true
jmeter.save.saveservice.sample_count=false
jmeter.save.saveservice.idle_time=true
5. 准备好脚本,例如存放在D:\01Test\02Jmeter\scripts\test
6. 将apache-jmeter-3.1\extras下的ant-jmeter-1.1.1.jar放在ant\lib下
7. Ant配置build.xml
l 将apache-jmeter3.1\extras中的build.xml复制到ant\bin下,并进行配置保存。
<?xml version="1.0" encoding="GBK"?>
<!-- 该配置文件作用为使用Ant来批量构建jmeter下loadtests文件夹里面的所有脚本,并按照指定格式来生成报告-->
<project name="ant-jmeter-test" default="all" basedir="D:\01Test\02Jmeter\apache-jmeter-3.1">
<tstamp>
<format property="time" pattern="2017-09-01" />
</tstamp>
<!-- 生成的报告的前缀和定义结果集的相关参数-->
<property name="ReportName" value="TestReport" />
<!-- 本地Jmeter目录-->
<property name="jmeter.home" value="D:\01Test\02Jmeter\apache-jmeter-3.1" />
<!-- 应生成的jtl和html报告的路径-->
<property name="jmeter.result.jtl.dir" value="D:\01Test\02Jmeter\scripts\test" />
<property name="jmeter.result.html.dir" value="D:\01Test\02Jmeter\scripts\test"/>
<target name="all">
<antcall target="test" />
<antcall target="report" />
</target>
<!-- 测试脚本-->
<target name="test">
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
<!-- jtl应存放路径和名称-->
<jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtl.dir}\jmeter_result.jtl">
<!-- 要运行的脚本。"*.jmx"指 包含此目录下的所有jmeter脚本-->
<testplans dir="${jmeter.result.jtl.dir}" includes="*.jmx" />
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="jmeter.save.saveservice.bytes" value="true"/>
<property name="file_format.testlog" value="${format}"/>
<property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>
</jmeter>
</target>
<!-- 生成报告 jtl路径和名称、html路径和名称 如需要多生成报告,则对写几个xslt即可-->
<target name="report">
<!--年月日时分秒时间戳 格式可修改-->
<tstamp prefix="build.">
<format property="TimeSign" pattern="yyyyMMddHHmmss"/>
</tstamp>
<xslt
in="${jmeter.result.jtl.dir}\jmeter_result.jtl"
<!--报告名称带有年月日时分秒-->
out="${jmeter.result.html.dir}\jmeter_DetailsReport-${build.TimeSign}.html"
style="${jmeter.home}\extras\jmeter.results.shanhe.me.xsl" />
<xslt
in="${jmeter.result.jtl.dir}\jmeter_result.jtl"
<!--报告名称带有年月日-->
out="${jmeter.result.html.dir}\jmeter_SummaryReport-${DSTAMP}.html"
style="${jmeter.home}\extras\jmeter-results-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>
l win+R输入cmd进入cmd.exe,执行ant -buildfile build.xml,即可成功。
8. Jenkins下载、安装、启动
l 下载:https://jenkins.io/download/,下载左边稳定版
l 安装:默认
l 登录localhost:8080,首次登录用户名为administrator,密码为提示文件中的内容,复制过来即可登录,登录后设置自己的用户名和密码即可
l 插件:首页->系统设置->管理插件->可选插件,搜索Performance plugin(Jmeter报告需要),安装此插件;
l Jenkins相关配置参考:
http://blog.csdn.net/qi_lin7/article/details/52045713
http://www.cnblogs.com/chenchen-tester/p/6930200.html
以前走的弯路,及遇到的错误问题
1、如提示错误:2 字节 UT8-8 序列的字节 2无效,则将build文件用notepad++打开,在编码选择“以UTF-8无BOM格式编码”,然后保存。
2、java(TM) platform se binary 已停止工作
build配置文件按如下网页修改
http://www.cnblogs.com/test2016/p/5342065.html
3、${lib.dir} does not exist.
将以下内容注释掉:
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan*.jar"/>
<fileset dir="${lib.dir}" includes="serializer*.jar"/>
</path>
4、The following error occurred while executing this line:
解决办法:未确认
Variable name: _JAVA_OPTIONS
Variable value: -Xmx512M
5、jmeter jar file not found or not a valid file:
D:\01Test\02Jmeter\bin\ApacheJMeter.jar
解决:Jmeter路径不对
6、java.lang.IllegalAccessError:
tried to access class org.apache.xml.serializer.ExtendedContentHandler from class org.apache.xalan.transformer.TransformerImpl
ant下lib下有xalan*.jar,serializer*.jar,删除即可
7、The <copy> type doesn‘t support nested text data ("86 90").
可能是粘贴过去的内容不兼容,重新编写一遍即可
原文地址:https://www.cnblogs.com/jxba/p/9218407.html