jmeter+jenkins+ant+git 实现持续集成

jmeter+jenkins+ant基础版:https://www.cnblogs.com/erchun/p/13446446.html

 

加上git进阶版参考:https://www.cnblogs.com/qiaoyeye/p/7122356.html

 

 

重点1:修改build.xml文件

把git拉取的代码放在jenkins的workspace工作区间里,所以要改 GIT拉取到本地目录路径

可以把jmeter生成报告的路径也改到工作区间中

xml version="1.0" encoding="UTF-8"?>
<project name="ant-jmeter-test" default="run" basedir=".">
    <tstamp> 
         
        <format property="datetime" pattern="yyyyMMddhhmm" />
    tstamp>
    <property environment="env"/>
    
    <property name="jmeter.home" value="D:\apache-jmeter-5.2.1" />
    <property name="report.title" value="jmeter接口自动化测试"/>
    
    <property name="jmeter.result.jtl.dir" value="${env.WORKSPACE}/results/${env.BUILD_ID}" />
    
    <property name="jmeter.result.html.dir" value="${env.WORKSPACE}/results/${env.BUILD_ID}" />
    
    <property name="ReportName" value="TestReport" />
    <property name="jmeter.result.jtlName" value="${jmeter.result.jtl.dir}/${ReportName}${datetime}.jtl" />
    <property name="jmeter.result.htmlName" value="${jmeter.result.html.dir}/${ReportName}${datetime}.html" />
    
    <property name="detail" value="_detail" />
    <property name="jmeter.result.jtlNamedetail" value="${jmeter.result.jtl.dir}/${ReportName}${datetime}.jtl" />
    <property name="jmeter.result.htmlNamedetail" value="${jmeter.result.html.dir}/${ReportName}${datetime}${detail}.html" />
    
    <property name="githome" value="${env.WORKSPACE}" />

    <target name="run">
        <antcall target="clean" />
        <antcall target="test" />
        <antcall target="report" />
    target>
    
     
     <target name="clean">
        <mkdir dir="${env.WORKSPACE}/results/${env.BUILD_ID}" />
    target>

    <target name="test">
        <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" />
        <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}">
            
            <testplans dir="${githome}" includes="*.jmx" />

            <property name="jmeter.save.saveservice.output_format" value="xml"/>
        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">
        <tstamp> <format property="report.datestamp" pattern="yyyy/MM/dd HH:mm" />tstamp>
        
        
        <xslt
              classpathref="xslt.classpath"
              force="true"
              in="${jmeter.result.jtlName}"
              out="${jmeter.result.htmlName}"
              style="${jmeter.home}/extras/jmeter.results.shanhe.me.xsl">
              <param name="dateReport" expression="${report.datestamp}"/>
       xslt>
       
       <xslt 
          classpathref="xslt.classpath"
          force="true"
          in="${jmeter.result.jtlNamedetail}"
          out="${jmeter.result.htmlNamedetail}"
          style="${jmeter.home}/extras/jmeter-results-detail-report_21.xsl">
          <param name="dateReport" expression="${report.datestamp}"/>
       xslt>

                
        <copy todir="${jmeter.result.html.dir}">
            <fileset dir="${jmeter.home}/extras">
                <include name="collapse.png" />
                <include name="expand.png" />
            fileset>
        copy>
    target>

project>

 

重点2:源码管理中加上从git上拉取

jmeter+jenkins+ant+git 实现持续集成_第1张图片

 

 

重点3:添加windows cmd构建

jmeter+jenkins+ant+git 实现持续集成_第2张图片

 

 

echo %WORKSPACE%
echo %BUILD_ID%
cd results
cd %BUILD_ID%

 

重点4:html报告路径可以换成jenkins工作区间里的路径

jmeter+jenkins+ant+git 实现持续集成_第3张图片

 result\$BUILD_ID默认jenkins工作区间下的路径

 

 jmeter+jenkins+ant+git 实现持续集成_第4张图片

 

 

 

附:

1、BUILD_ID和WORKSPACE为jenkins的可用环境变量

jmeter+jenkins+ant+git 实现持续集成_第5张图片

 

 用法可参考:http://www.mamicode.com/info-detail-2771313.html、https://www.cnblogs.com/puresoul/p/4828913.html

 

2、Ant常用Target:

clean:https://blog.csdn.net/weixin_30699831/article/details/99817366

jmeter+jenkins+ant+git 实现持续集成_第6张图片

 或者还可以勾选git上的每次构建之前清除工作区间

jmeter+jenkins+ant+git 实现持续集成_第7张图片

 

 

 

3、${env.WORKSPACE}用法

Ant Property:https://blog.csdn.net/asty9000/article/details/78953663、https://www.cnblogs.com/gzhu/archive/2013/05/15/3080026.html

jmeter+jenkins+ant+git 实现持续集成_第8张图片

 

你可能感兴趣的:(jmeter+jenkins+ant+git 实现持续集成)