jenkins / ant / jmeter 持续集成接口自动化

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>

时间: 2024-10-12 16:27:37

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

jenkins, ant, pmd持续集成

http://pmd.sourceforge.net/pmd-5.0.3/ant-task.html 在jenkins , ant , pmd进行集成的时候,build.xml模板如下,在网上找了一些模板,大部分都是A,B,C,D....狂copy,所以错的地方都一模一样 我这份已经自己试过,只要改下你们自己对应的目录即可. <?xml version="1.0" encoding="UTF-8"?> <project name="pmd

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

写在前面 我们以前windows跑.net Framework程序的时候,发布,自己乖乖的替换程序:备份,也是自己一个一个的重命名备份:回滚,发布遇到问题的回滚更是不用说了:运维很是怕我们 这些用windows的啊: 那全面拥抱linux的一一.net core 时代 ,是如何处理这些个问题的呢? 噔噔蹬蹬~请往下看. 运行环境 centos:7.2 cpu:1核 2G内存 1M带宽 Jenkins ver. 2.150.1 一台安装jenkins的机器. (本文例子不一定要安装jenkins,

jenkins+ant+jmeter接口自动化测试(持续构建)

使用badboy录制脚本,到处到jmeter后进行接口自动化,后来想着 可不可以用自动化来跑脚本呢,不用jmeter的图形界面呢, 选择了ant来进行构建,最后想到了用Jenkins来进行持续构建接口测试. 上一篇讲到了badboy录制jmeter脚本后,可以在jmeter进行回访, 其实也可以直接在jmeter进行录制脚本,我们打开jmeter, 打开我们的代理服务器,然后设置 设置后呢,我们点击启动,这样就可以启动代理服务器了,  我录的是手机,所以呢,我在cmd 输入ipconfig获取地

Jenkins+Ant+Jmeter接口自动化集成测试实例

Jenkins+Ant+Jmeter接口自动化集成测试实例 一.Jenkins安装配置 1.安装配置JDK1.6+环境变量: 2.下载jenkins.war,放入C:\jenkins目录下,目录位置随意: Jenkins启动方法: cmd进入Jenkins目录下,执行java -jar jenkins.war 浏览器输入:localhost:8080可以访问Jenkins表示配置成功: 二.Ant安装配置 1.下载apache-ant-1.9.6:放入E盘,如E:\apache-ant-1.9.

Jenkins+Ant+Jmeter 自动化性能测试平台

一.前言 持续集成 持续集成是一种软件开发实践,即团队开发成员经常集成他们的工作, 通常每个成员每天至少集成一次,也就意味着每天可能会发生多次集成.每次集成都通过自动化的构建(包括编译,发布,自动化测试)来验证,从而尽快地发现集成错误.许多团队发现这个过程可以大大减少集成的问题,让团队能够更快的开发内聚的软件. Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括:持续的软件版本发布/测试项目,监控外部调用执行的工作. 项目构建 通过构建工具对多个项目文件进行统一

jenkins+ant+jmeter自动化性能测试平台

jenkins+ant+jmeter自动化性能测试平台 Jmeter是性能测试的工具,java编写.开源,小巧方便,可以图形界面运行也可以在命令行下运行.网上已经有人使用ant来运行,http://www.programmerplanet.org/projects/jmeter-ant-task/,既然可以使用ant运行,那和hudson.jenkins集成就很方便了,而且jenkins上也有相应的插件Performance Plugin,可以自动收集jmeter的测试结果,展示出来. 首先去下

Jenkins持续集成-自动化部署脚本的实现《python》

读者须知:1.本手记本着记续接前面的两张手记内容整理2.本手记针对tomcat部署测试环境实现 最近工作比较繁忙,导致这章一直拖延,没有太抽出时间来总结.要实现Jenkins端的持续集成,其实在CI服务配置端很容易,难点呢?就是如何实现自动化的部署.我的脚本设计就是为了解决以下难题: 难点一.如何使得自动化部署脚本更通用 我用的脚本,依赖依赖一个配置文件的模块化,让每一个应用业务模块更加通用.自动化所执行的命令呢?我也是设计想法本着更加通用平台的原则,至少对于tomcat+java or jav

.NET 半天搭建Jenkins持续集成与自动化部署系统

前言 相信每一位程序员都经历过深夜加班上线的痛苦!而作为一个加班上线如家常便饭的码农,更是深感其痛.由于我们所做的系统业务复杂,系统庞大,设计到多个系统之间的合作,而核心系统更是采用分布式系统架构,由于当时对系统划分的不合理等等原因导致每次发版都会设计到多个系统的发布,小的版本三五个,大的版本十几个甚至几十个系统的同时发布!而我们也没有相应的基础设施的支撑,发版方式更是最传统的,开发人员将发布包发给运维人员,由其讲各个发布包一个一个覆盖到生产环境.因此每次上线仅仅发版就需要2-3个小时.这种方式

Jenkins+Ant+JMeter报告自动化

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&