Configuration of Jmeter ant jekins environment variables

Insert picture description here

Insert picture description hereConfigure ANT environment variable
ANT_HOME: ANT installation path
Insert picture description here
path:
Insert picture description here

classpath:
Insert picture description here
folder structure:
Insert picture description here

Configure build file

<?xml version="1.0" encoding="utf-8"?>
<project name="pc" default="all" basedir="E:\BaiduNetdiskDownload\test\JmeterAutoTest">
    <tstamp>
        <format property="time" pattern="yyyyMMddhhmm" />
    </tstamp>
    <!-- 需要改成自己本地的 Jmeter 目录-->
    <property name="jmeter.home" value="E:\BaiduNetdiskDownload\apache-jmeter-2.12\apache-jmeter-2.12" />
    <!-- jmeter生成jtl格式的结果报告的路径-->
    <property name="jmeter.result.jtl.dir" value="E:\BaiduNetdiskDownload\test\JmeterAutoTest\pc\resultlog\jtl" />
    <!-- jmeter生成html格式的结果报告的路径-->    
    <property name="jmeter.result.html.dir" value="E:\BaiduNetdiskDownload\test\JmeterAutoTest\pc\resultlog\html" />
    <!-- 生成的报告的前缀 -->
    <property name="ReportName" value="TestReport" />
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${time}.jtl" />
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${time}.html" />
    <!-- 接收测试报告的邮箱 -->
    <property name="mail_from" value="发送邮箱" />
    <property name="mail_to" value="接收邮箱" />
    <!-- 电脑地址 -->
     <!-- <property name="ComputerName" value="jkqsh-l0285" />-->
    <target name="all">
        <antcall target="test" />
        <antcall target="report" />
		<antcall target="send" />
    </target>
    <target name="test">
        <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeter jmeterhome="${
    
    jmeter.home}" resultlog="${
    
    jmeter.result.jtlName}">
            <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本 -->
            <testplans dir="E:\BaiduNetdiskDownload\test\JmeterAutoTest\pc\script" />
        </jmeter>
    </target>

    <path id="xslt.classpath">
        <fileset dir="${
    
    jmeter.home}/lib" includes="xalan*.jar"/>
        <fileset dir="${
    
    jmeter.home}/lib" includes="serializer*.jar"/>
    </path>

    <target name="report">
        <xslt
	    classpathref="xslt.classpath"
            force="true"
	    in="${
    
    jmeter.result.jtlName}" 
	    out="${
    
    jmeter.result.htmlName}" 
	    style="${
    
    jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
            <param name="dateReport" expression="${
    
    time}"/>
	</xslt>
        <!-- 因为上面生成报告的时候,不会将相关的图片也一起拷贝至目标目录,所以,需要手动拷贝 -->
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            </fileset>
        </copy>
    </target>
    <!-- 发送邮件 -->
	<target name="send" >
        <mail mailhost="smtp.126.com" mailport="25" subject="Test Report!" messagemimetype="text/html" user="邮箱名" password="邮箱密码(这个密码不一定是正常登陆的密码,可能需要在邮箱的设置中,设置获取smtp相关的密码)" >
        <from address="${
    
    mail_from}"/>
        <to address="${
    
    mail_to}"/>
        <message>This email was sent automatically by ANT. Please check the automation test report. Thank you!</message>
		<attachments> 
			<fileset dir="${
    
    jmeter.result.html.dir}">
				<include name="${
    
    ReportName}${
    
    time}.html"/>
			</fileset>
		</attachments>
		</mail>
    </target>
</project>

Use ANT to send test report:
Insert picture description here
put the jenkins file package into tomocat's webapps directory:
Insert picture description here
start tomocat: double-click startup.bat in the tomocat bin directory (under Windows) to
open jenkins:
enter in the browser: http://localhost:8080 /jenkins/
Use jenkins:
Reference: https://blog.csdn.net/zhangxiaoPH/article/details/78665884

Guess you like

Origin blog.csdn.net/KathyLJQ/article/details/107051241