Jmeter+Ant+Jenkins配合使用可以做持续集成
首先先下载 Ant 并配置换环境变量
下载地址-》Ant 官网
一般进来的时候都是显示最近更新的一条记录
下载成功后,如果是Windows直接解压就行了,如果是linux则直接使用 解压命令,(.zip包) unzip 包 进行解压 。如果下载的是tar.gz包
就用 tar -zxvf 包 进行解压, -z的意思是格式(gz) -Z(bz2) gz) -Z(bz2) 其余的忘了,可以百度。 然后x 是解压,相对的c就是打包 命令 v 是打包或者解压的时候详细查看,特别是解压的时候,会看到一堆的文件。命令 f 就是文件咯
解压完以后就开始配置了,
配置的时候可以看下官方文档 Ant 官方文档解释说明
CLASSPATH要不要配置呢,继续看下面的说明
Ant 1.7.0 以后就可以不用配置 /usr/share/ant/lib
配置环境变量的流程可以参考 Jmeter环境变量配置 或者 Java环境变量配置
新建 ANT_HOME 值为 E:\apache-ant-1.10.7 然后在path中添加 %ANT_HOME%/bin
配置成功后,在DOC窗口使用 ant -version 能查看到信息就可以了
顺便分析个网上一位博主的博客:博主 如他文中描述,需要配置无变量才能访问,但是他忽略了 它的路径写错了 。必须是 / 而不能是 \ 同时path的路径不宜过长,是否配对了,也可以在DOC窗口打印命令 set 或者 path 进行查看
当 Ant 配置成功后,将Jmeter里面的extras的ant-jmeter-1.1.1.jar包复制到 ant 的安装目录的lib下
ant 目录
以上完成后就是对Build.xml文件进行修改
在Jmeter的extras目录下有个build.xml的文件,建议将它拷贝出来,新建一个目录复制到里面去。接下来需要用到extras目录下面的有几个文件: build.xml. collapse.png,expand.png, jmeter-results-detail-report_21.xsl
以下是我自己试验过的数据
这是修改后的文件,亲测可用,但是有冗余部分,看的懂的可以自行修改。 然后在这个目录下直接输入ant 命令,不用带文件名除非build的文件名被修改,文件名修改的话,使用 ant -f 修改的文件名,具体命令 使用 ant -help进行查看
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project name="ant-jmeter" default="all">
<description>
Sample build file for use with ant-jmeter.jar
See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php
To run a test and create the output report:
ant -Dtest=script
To run a test only:
ant -Dtest=script run
To run report on existing test output
ant -Dtest=script report
The "script" parameter is the name of the script without the .jmx suffix.
Additional options:
-Dshow-data=y - include response data in Failure Details
-Dtestpath=xyz - path to test file(s) (default user.dir).
N.B. Ant interprets relative paths against the build file
-Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
-Dreport.title="My Report" - title for html report (default is 'Load Test Results')
</description>
<property name="result_report" value="C:\Users\Administrator\Desktop\Forder\tempTest\htmlreport"/>
<property name="test_plan" value="C:\Users\Administrator\Desktop\Forder\tempTest"/>
<property name="jmeter_extras" value="E:\apache-jmeter-4.0\extras"/>
<property name="jmeter_lib" value="E:\apache-jmeter-4.0\lib"/>
<property name="jmeter.home" value="E:\apache-jmeter-4.0"/>
<property name="report.title" value="Load Test Results"/>
<!-- Name of test (without .jmx) -->
<property name="test" value="Test"