使用場景:
多人協作,共同完成腳本的編寫,腳本之間進行合並后,用遠程構建運行腳本。做接口的輪訓測試
基本的配置與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