1、 将 jmeter 脚本放在/var/lib/jenkins/workspace/Jmeter_auto/jmxpath路径下

2、 点击http://jk.facebank.net.cn/job/Jmeter_auto/立即构建即可

最终生成的报告会在 /var/lib/jenkins/workspace/Jmeter_auto/jmxpath/时间目录/html/文件夹中,里面包含整个脚本运行的结果

jmeter 安装目录:

/var/lib/apache-jmeter-3.0, ant中原始的build.xml是在jmeter就有的,/var/lib/apache-jmeter-3.0/extras下

ant 安装目录:

/var/lib/apache-ant-1.9.6  ,需要将jmeter中的多个配置都拷贝到ant目录下一份

build.xml, jmeter-results-detail-report_21.xsl,collapse.png,expand.png

原理如下:

1、jenkins 调用ant 的build.xml 进行构建

2、ant的build.xml可调用jmeter的脚本(jmx) 生成jtl内容,

3、将jtl依据jmeter-results-report_21.xsl 转变为html测试报告

附件中 build.xml只能对一个jmx文件进行操作

build2.xml可以对多个jmx文件进行操作

ant-cortrib-1.0b3.jar 是对多个jmx文件进行操作必须的Jar包,使用foreach的包

并必须在build.xml添加如下内容:

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/var/lib/apache-ant-1.9.6/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

http://ant-contrib.sourceforge.net/ 对ant-contrib.jar的说明

jmeter-results-detail-report_21.xsl

ant-contrib-1.0b3.jar

build2.xml

build.xml

build.xml 文件

<?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')

Deprecated:
-Dformat=2.0 - use version 2.0 JTL files rather than 2.1

</description>

<property name="testpath" value="/var/lib/jenkins/workspace/Jmeter_auto/jmxpath"/>
<property name="jmeter.home" value="/var/lib/apache-jmeter-3.0/"/>
<property name="report.title" value="Load Test Results"/>
<property name="jmeter.classpath" value="/var/lib/apache-jmeter-3.0/"/>
<!-- Name of test (without .jmx) -->
<property name="test" value="HTTPCOOK"/>

<!-- Should report include response data for failures? -->
<property name="show-data" value="n"/>

<property name="format" value="2.1"/>

<condition property="style_version" value="">
<equals arg1="${format}" arg2="2.0"/>
</condition>

<condition property="style_version" value="_21">
<equals arg1="${format}" arg2="2.1"/>
</condition>

<condition property="funcMode">
<equals arg1="${show-data}" arg2="y"/>
</condition>

<condition property="funcMode" value="false">
<not>
<equals arg1="${show-data}" arg2="y"/>
</not>
</condition>

<!-- Allow jar to be picked up locally -->
<path id="jmeter.classpath">
<pathelement location="/var/lib/apache-ant-1.9.6/lib/ant-jmeter-1.1.1.jar" />
<!-- <fileset dir="/var/lib/apache-ant-1.9.6">
<include name="ant-jmeter*.jar"/>
</fileset>
-->
</path>

<taskdef
name="jmeter"
classpathref="jmeter.classpath"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

<target name="all" depends="run,report"/>

<target name="run">
<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/${test}.html"/>
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl">
<!--
<jvmarg value="-Xincgc"/>
<jvmarg value="-Xmx128m"/>
<jvmarg value="-Dproperty=value"/>
<jmeterarg value="-qextra.properties"/>
-->
<!-- Force suitable defaults -->
<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}"/>

<property name="jmeter.save.saveservice.response_data" value="true"/>
<property name="jmeter.save.saveservice.samplerData" value="true"/>
<property name="jmeter.save.saveservice.responseHeaders" value="true"/>
<property name="jmeter.save.saveservice.requestHeaders" value="true"/>
<property name="jmeter.save.saveservice.encoding" value="true"/>
<property name="jmeter.save.saveservice.url" value="true"/>
<property name="jmeter.save.saveservice.filename" value="true"/>
<property name="jmeter.save.saveservice.hostname" value="true"/>
<property name="jmeter.save.saveservice.thread_counts" value="true"/>
<property name="jmeter.save.saveservice.sample_count" value="true"/>
<property name="jmeter.save.saveservice.idle_time" value="true"/>
<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>

<property name="lib.dir" value="${jmeter.home}/lib"/>

<!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+ -->
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan*.jar"/>
<fileset dir="${lib.dir}" includes="serializer*.jar"/>
</path>

<target name="report" depends="xslt-report,copy-images">
<echo>Report generated at ${report.datestamp}</echo>
</target>

<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/${test}.jtl"
out="${testpath}/${test}.html"
style="/var/lib/apache-ant-1.9.6/jmeter-results-detail-report_21.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>

<!-- Copy report images if needed -->
<target name="copy-images" depends="verify-images" unless="samepath">
<copy file="/var/lib/apache-ant-1.9.6/expand.png" tofile="${testpath}/expand.png"/>
<copy file="/var/lib/apache-ant-1.9.6/collapse.png" tofile="${testpath}/collapse.png"/>
</target>

<target name="verify-images">
<condition property="samepath">
<equals arg1="${testpath}" arg2="${basedir}" />
</condition>
</target>

<!-- Check that the xalan libraries are present -->
<condition property="xalan.present">
<and>
<!-- No need to check all jars; just check a few -->
<available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
</and>
</condition>

<target name="_message_xalan" unless="xalan.present">
<echo>Cannot find all xalan and/or serialiser jars</echo>
<echo>The XSLT formatting may not work correctly.</echo>
<echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
</target>

</project>

build2.xml

<?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')

Deprecated:
-Dformat=2.0 - use version 2.0 JTL files rather than 2.1

</description>

<property name="testpath" value="/var/lib/jenkins/workspace/Jmeter_auto/jmxpath"/>
<property name="jmeter.home" value="/var/lib/apache-jmeter-3.0/"/>
<property name="report.title" value="Load Test Results"/>
<property name="jmeter.classpath" value="/var/lib/apache-jmeter-3.0/"/>
<property name="results.jtl" value="jtl"/>
<property name="results.html" value ="html"/>
<property name="runremote" value="false"/>
<property name="report.title" value="WebLoad Test Report"/>
<tstamp><format property="report.datestamp" pattern="yyyy-MM-dd-HH-mm-ss"/></tstamp>
<property name="time" value="${report.datestamp}"/>
<property name = "interval-time-in-seconds" value ="10"/>
<!-- Name of test (without .jmx) -->
<!-- <property name="test" value="HTTPCOOK"/> -->

<!-- Should report include response data for failures? -->
<property name="show-data" value="n"/>

<property name="format" value="2.1"/>

<condition property="style_version" value="">
<equals arg1="${format}" arg2="2.0"/>
</condition>

<condition property="style_version" value="_21">
<equals arg1="${format}" arg2="2.1"/>
</condition>

<condition property="funcMode">
<equals arg1="${show-data}" arg2="y"/>
</condition>

<condition property="funcMode" value="false">
<not>
<equals arg1="${show-data}" arg2="y"/>
</not>
</condition>

<!-- Allow jar to be picked up locally -->
<path id="jmeter.classpath">
<pathelement location="/var/lib/apache-ant-1.9.6/lib/ant-jmeter-1.1.1.jar" />
<!-- <fileset dir="/var/lib/apache-ant-1.9.6">
<include name="ant-jmeter*.jar"/>
</fileset>
-->
</path>

<taskdef
name="jmeter"
classpathref="jmeter.classpath"
classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="/var/lib/apache-ant-1.9.6/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>

<!--运行之前首先创建临时结果文件夹-->
<target name="create-folder">
<delete dir="${testpath}/temp"/>
<mkdir dir="${testpath}/temp/${results.jtl}" />
<mkdir dir="${testpath}/temp/${results.html}" />
</target>

<target name="all-test" depends="create-folder">
<foreach target="test1" param="jmxfile" >
<fileset dir="/var/lib/jenkins/workspace/Jmeter_auto/jmxpath/">
<include name="*.jmx" />
</fileset>
</foreach>
</target>

<target name="test1" >
<basename property="jmx.filename" file="${jmxfile}" suffix=".jmx"/>
<echo message="---------- Processing ${jmxfile} -----------"/>
<echo message="resultlogdir===${testpath}/temp/${results.jtl}"/>
<jmeter jmeterhome="${jmeter.home}" resultlogdir="${testpath}/temp/${results.jtl}" runremote="${runremote}" resultlog="${jmx.filename}.jtl"
testplan="/var/lib/jenkins/workspace/Jmeter_auto/jmxpath/${jmx.filename}.jmx">
<!-- <jvmarg value="-Xincgc"/>
<jvmarg value="-Xms1024m"/>
<jvmarg value="-Xm1024m"/>
-->
</jmeter>
<sleep seconds="20"></sleep>
<!--Generate html report-->

<xslt in="${testpath}/temp/${results.jtl}/${jmx.filename}.jtl"
out="${testpath}/temp/${results.html}/${jmx.filename}.html" classpathref="xslt.classpath"
style="${jmeter.home}/extras/jmeter-results-report_21.xsl" >
<param name="dateReport" expression="${report.datestamp}"/>
<param name="showData" expression="n"/>
<param name="titleReport" expression="${report.title}:[${jmx.filename}]"/>
</xslt>

<echo message="Sleep ${interval-time-in-seconds} Seconds, and then start next Test; Please waiting ......"/>
<sleep seconds="${interval-time-in-seconds}"></sleep>
</target>

<target name="copy-images" depends="all-test">
<copy file="${jmeter.home}/extras/expand.png" tofile="${results.html}/expand.png"/>
<copy file="${jmeter.home}/extras/collapse.png" tofile="${results.html}/collapse.png"/>
<copydir src="${testpath}/temp" dest="${testpath}/${report.datestamp}"/>
<delete dir="${testpath}/temp"/>
</target>

<target name="all" depends="all-test, copy-images" />
<!--
<jvmarg value="-Xincgc"/>
<jvmarg value="-Xmx128m"/>
<jvmarg value="-Dproperty=value"/>
<jmeterarg value="-qextra.properties"/>
-->
<!-- Force suitable defaults -->
<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}"/>

<property name="jmeter.save.saveservice.response_data" value="true"/>
<property name="jmeter.save.saveservice.samplerData" value="true"/>
<property name="jmeter.save.saveservice.responseHeaders" value="true"/>
<property name="jmeter.save.saveservice.requestHeaders" value="true"/>
<property name="jmeter.save.saveservice.encoding" value="true"/>
<property name="jmeter.save.saveservice.url" value="true"/>
<property name="jmeter.save.saveservice.filename" value="true"/>
<property name="jmeter.save.saveservice.hostname" value="true"/>
<property name="jmeter.save.saveservice.thread_counts" value="true"/>
<property name="jmeter.save.saveservice.sample_count" value="true"/>
<property name="jmeter.save.saveservice.idle_time" value="true"/>
<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}"/>

<property name="lib.dir" value="${jmeter.home}/lib"/>

<!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+ -->
<path id="xslt.classpath">
<fileset dir="${lib.dir}" includes="xalan*.jar"/>
<fileset dir="${lib.dir}" includes="serializer*.jar"/>
</path>

<!-- <target name="report" depends="xslt-report,copy-images">
<echo>Report generated at ${report.datestamp}</echo>
</target>
-->
<!-- <target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/${test}.jtl"
out="${testpath}/${test}.html"
style="/var/lib/apache-ant-1.9.6/jmeter-results-detail-report_21.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>
-->
<!-- Copy report images if needed -->
<!-- <target name="copy-images" depends="verify-images" unless="samepath">
<copy file="/var/lib/apache-ant-1.9.6/expand.png" tofile="${testpath}/expand.png"/>
<copy file="/var/lib/apache-ant-1.9.6/collapse.png" tofile="${testpath}/collapse.png"/>
</target>
-->
<target name="verify-images">
<condition property="samepath">
<equals arg1="${testpath}" arg2="${basedir}" />
</condition>
</target>

<!-- Check that the xalan libraries are present -->
<condition property="xalan.present">
<and>
<!-- No need to check all jars; just check a few -->
<available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
</and>
</condition>

<target name="_message_xalan" unless="xalan.present">
<echo>Cannot find all xalan and/or serialiser jars</echo>
<echo>The XSLT formatting may not work correctly.</echo>
<echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
</target>

</project>

jenkins / ant / jmeter 持续集成接口自动化的更多相关文章

  1. Jenkins+Ant+Jmeter搭建轻量级接口自动化

    软件准备 本文所用软件版本如下: Jenkins2.176.1 Tomcat9.0.21 Ant1.9.14 Jmeter5.1.1 我已经把相应的软件上传到我的网盘中,下载地址如下: 下载链接:ht ...

  2. Asp.net Core 使用Jenkins + Dockor 实现持续集成、自动化部署(三):搭建jenkins集群环境

    写在前面 大家可以看到本文的配图,左边是jenkins单机环境,右边是jenkins集群.个中区别,不言而喻,形象生动. 前面我分别介绍了.net core 程序的多种部署方式(无绝对孰优孰劣): 1 ...

  3. Asp.net Core 使用Jenkins + Dockor 实现持续集成、自动化部署(二):部署

    前面又是废话 我之前写过: Asp.Net Core 程序部署到Linux(centos)生产环境(一):普通部署 Asp.Net Core 程序部署到Linux(centos)生产环境(二):doc ...

  4. Asp.net Core 使用Jenkins + Dockor 实现持续集成、自动化部署(一):Jenkins安装

    2019/1/31更新,经过我一段时间的使用 建议大家的jenkins还是不要使用docker方式安装 建议大家的jenkins还是不要使用docker方式安装 建议大家的jenkins还是不要使用d ...

  5. Jenkins +Ant +Jmeter(apache-jmeter-5.1.1)自动化性能测试平台

    1.安装配置好Jdk, 下载网址:https://www.cr173.com/soft/33894.html 2.Jmeter下载地址:http://jmeter.apache.org/downloa ...

  6. jenkins, ant, pmd持续集成

    http://pmd.sourceforge.net/pmd-5.0.3/ant-task.html 在jenkins , ant , pmd进行集成的时候,build.xml模板如下,在网上找了一些 ...

  7. Jmeter(二十八)_Docker+Jmeter+Gitlab+Jenkins+Ant(容器化的接口自动化持续集成平台)

    这套接口自动化持续集成环境已经部署差不多了,现在说说我的设计思路 1:利用Docker容器化Gitlab,Jenkins,Jmeter,Ant,链接如下 Docker_容器化gitlab Docker ...

  8. 持续集成接口自动化-jmeter+ant+jenkins(一)

    ant 批量执行Jmeter 一.环境准备 1.JDK环境:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2.A ...

  9. Asp.net Core 使用Jenkins + Dockor 实现持续集成、自动化部署(四):发布与回滚

    写在前面 我们以前windows跑.net Framework程序的时候,发布,自己乖乖的替换程序:备份,也是自己一个一个的重命名备份:回滚,发布遇到问题的回滚更是不用说了:运维很是怕我们 这些用wi ...

随机推荐

  1. ASP.NET Core管道深度剖析(1):采用管道处理HTTP请求

    之所以称ASP.NET Core是一个Web开发平台,源于它具有一个极具扩展性的请求处理管道,我们可以通过这个管道的定制来满足各种场景下的HTTP处理需求.ASP. NET Core应用的很多特性,比 ...

  2. 计算机程序的思维逻辑 (41) - 剖析HashSet

    上节介绍了HashMap,提到了Set接口,Map接口的两个方法keySet和entrySet返回的都是Set,本节,我们来看Set接口的一个重要实现类HashSet. 与HashMap类似,字面上看 ...

  3. PHP_环境配置_python脚本_2017

    Apache配置 需要安装:VC2015 httpd-2.4.16-win32-VC14.zip VC14就是2015的环境. 又比如:php-5.6.12-Win32-VC11-x86 VC11就是 ...

  4. JavaScript学习总结(三)——this、原型、javascript面向对象

    一.this 在JavaScript中this表示:谁调用它,this就是谁. JavaScript是由对象组成的,一切皆为对象,万物皆为对象.this是一个动态的对象,根据调用的对象不同而发生变化, ...

  5. 【基于WinForm+Access局域网共享数据库的项目总结】之篇二:WinForm开发扇形图统计和Excel数据导出

    篇一:WinForm开发总体概述与技术实现 篇二:WinForm开发扇形图统计和Excel数据导出 篇三:Access远程连接数据库和窗体打包部署 [小记]:最近基于WinForm+Access数据库 ...

  6. jQuery2.x源码解析(回调篇)

    jQuery2.x源码解析(构建篇) jQuery2.x源码解析(设计篇) jQuery2.x源码解析(回调篇) jQuery2.x源码解析(缓存篇) 通过艾伦的博客,我们能看出,jQuery的pro ...

  7. 回车去替换铵钮的click点击功能

    某一时候,我们不想在form的所有必填的域均完成之后,再去使用mouse去点击铵钮来提交数据.而是直接按回车去focus提交的铵钮来提交. 可以写jQuery script程序:

  8. C#开发微信门户及应用(25)-微信企业号的客户端管理功能

    我们知道,微信公众号和企业号都提供了一个官方的Web后台,方便我们对微信账号的配置,以及相关数据的管理功能,对于微信企业号来说,有通讯录中的组织架构管理.标签管理.人员管理.以及消息的发送等功能,其中 ...

  9. python学习笔记(python简史)

    一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum) 目前python主要应用领域: ·云计算 ·WEB开发 ·科学运算.人工智能 ·系统运维 ·金融:量化交 ...

  10. MySQL引擎、索引和优化(li)

    一.存储引擎 存储引擎,MySQL中的数据用各种不同的技术存储在文件(或者内存)中.这些技术中的每一种技术都使用不同的存储机制.索引技巧.锁定水平并且最终提供广泛的不同的功能和能力.通过选择不同的技术 ...