摘自:https://www.cnblogs.com/syw20170419/p/10732167.html

 

使用场景:

  多人协作,共同完成脚本的编写,脚本之间进行合并后,用远程构建运行脚本。做接口的轮训测试

 

基本的配置与Jenkins+Ant+SVN+Jmeter实现持续集成的配置一样,主要在Jenkins的配置上的区别会有所不同

 

安装的插件:

  enkins安装好之后,需要为其安装gitlab插件:在主面板上点击Manage Jenkins -> Manage Plugins,选择安装Gitlab Plugin和Gitlab Hook Plugin

      常用安装的插件:Ant plugin 、Git 、 Git Parameter、 GitHubAPI、  GitHubBranch Source、 SSH Slaces、Subversion (SVN的插件)

 

配置SSH key

       由于jenkins需要从gitlab上拉取代码,通过ssh方式

 

1、Jenkins的“配置”:

    

 

2、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-test" default="run" basedir=".">
  <tstamp>
      <format property="time" pattern="yyyyMMddHHmm" />
    </tstamp>
    
<!--<property name="testpath" value="${user.dir}"/> -->
<!-- jmeter的存放路径--> <property name="jmeter.home" value="/Users/apple/Downloads/Auto/apache-jmeter-5.1"/> <property name="jmeter.home" value="/Users/apple/Downloads/Auto/apache-jmeter-5.1" /> <!-- jmeter生成jtl格式的结果报告的路径--> <property name="jmeter.result.jtl.dir" value="/Users/apple/.jenkins/workspace/autotest-api/TestReport/jtl" /> <!-- jmeter生成html格式的结果报告的路径--> <property name="jmeter.result.html.dir" value="/Users/apple/.jenkins/workspace/autotest-api/TestReport/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" /> <!-- 输出生成的报告名称和存放路径--> <echo message="${jmeter.result.jtlName}"/> <echo message="${jmeter.result.htmlName}"/> <echo message="${jmeter.result.html.dir}"/> <target name="run"> <antcall target="test"/> <antcall target="report"/> </target> <!--加载jar包,解决显示时间问题--> <path id="xslt.classpath"> <fileset dir="${jmeter.home}/lib" includes="xalan*.jar"/> <fileset dir="${jmeter.home}/lib" includes="serializer*.jar"/> </path> <target name="test"> <taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask" /> <jmeter jmeterhome="${jmeter.home}" resultlog="${jmeter.result.jtlName}"> <!-- 声明要运行的脚本。"*.jmx"指包含此目录下的所有jmeter脚本-->

      <!--未使用Git前,可以给定目录拉取本地的脚本执行--> <!-- <testplans dir="/Users/iber/Test_group/jmeter/apache-jmeter-3.3/TestScrip_Lucky" includes="20_Interface_New.jmx”/>-->
    
      <!--添加Git后,修改路径,默认运行的脚本从Jenkins的workspace中拉取--> <testplans dir="/Users/apple/.jenkins/workspace/autotest-api" includes="20_Interface_New.jmx" /> <property name="jmeter.save.saveservice.output_format" value="xml"/> </jmeter> </target> <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"> <!--显示dateReport的时间--> <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>
复制代码

 

3、Git的操作

步骤:Git上创建对应的project--进入project--settings--Repository--Deploy Keys--添加自己电脑生成的key即可。

秘钥的生成与查看,详见链接:

如下是截图示例:

  

        

  Gitlab添加的是”公钥“

  

 

4、Jenkins的“Credentials" 中的配置。Credentials添加的是”私钥“

  

  凭证的添加如下:注意,如果在生成秘钥时,输入了密码,截图中的passphrase需要输入当时添加的秘钥

  

  如下的一种方式进行添加也行。

    

     

      

        

 

 注:一旦如上的一切配置好后:

  1、不可随意修改脚本的名称 20_Interface_New.jmx。

  2、不可删除build.xml文件

 

4、每次从Git拉取拉取代码,修改脚本后再次上传到Git即可,每次构建将自动拉取Git的代码运行

  

 

 

 

为何Jenkins需要用到Git的秘钥,详见文章:https://www.cnblogs.com/syw20170419/p/10732826.html 

 常看的网站:

github的SSH 秘钥说明:https://help.github.com/en/articles/about-ssh

查看/修改Jenkins目前的时区:https://www.cnblogs.com/jwentest/p/7715786.html

 

查看Jenkins的配置信息:http://192.168.0.167:8080/jenkins/systemInfo

 

官网给出修改时区的建议:https://wiki.jenkins.io/display/JENKINS/Change+time+zone

 

世界时区列表:https://www.jianshu.com/p/3d99df03f540

 

定时任务(比较全的介绍定时时间的设置):http://www.cnblogs.com/ycyzharry/p/7598337.html

 

 

 

1.作者:Syw 
2.出处:http://www.cnblogs.com/syw20170419/ 
3.本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 
4.如果文中有什么错误,欢迎指出。以免更多的人被误导。