Jenkinsfile 构建 接口自动化
1.git 上维护一份Jenkinsfile文件,内容如下:
pipeline {
agent any
stages {
stage('pull JMX') {
steps { //从git拉取代码
git credentialsId: '3d010dc0-2220-4ec1-9a5e-f139c077dce3', url: 'http://192.168.184.149:82/test_group/autotest.git'
}
}
stage('RUN') {
steps { //执行sh command
sh '/opt/ant/bin/ant -file build.xml run'
}
}
stage('format report') {
steps {
script{ //执行 Groovy 代码
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP","")
}
}
}
}
post {
always {
publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: '/root/test_report/html', reportFiles: 'TestReport.html', reportName: 'HTML Report', reportTitles: 'AUTOTEST'])
}
}
}
如下:
- Jenkinsfile steps中的内容说明:
stage - pull code:
stage - run: 固定写法
stage - post - always:
3.pipeline 项目中的配置
- 构建成功
Started by user zhangsan
Obtained Jenkinsfile from git http://192.168.184.149:82/test_group/autotest.git
[Pipeline] Start of Pipeline
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/auto_test_pipline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential 3d010dc0-2220-4ec1-9a5e-f139c077dce3
> git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/auto_test_pipline/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://192.168.184.149:82/test_group/autotest.git # timeout=10
Fetching upstream changes from http://192.168.184.149:82/test_group/autotest.git
> git --version # timeout=10
> git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials gitlab-auth-http
> git fetch --tags --progress http://192.168.184.149:82/test_group/autotest.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 597072787d61638e570237f69adb11189aa92a40 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 597072787d61638e570237f69adb11189aa92a40 # timeout=10
Commit message: "update"
> git rev-list --no-walk 597072787d61638e570237f69adb11189aa92a40 # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (pull JMX)
[Pipeline] git
The recommended git tool is: NONE
using credential 3d010dc0-2220-4ec1-9a5e-f139c077dce3
> git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/auto_test_pipline/.git # timeout=10
Fetching changes from the remote Git repository
> git config remote.origin.url http://192.168.184.149:82/test_group/autotest.git # timeout=10
Fetching upstream changes from http://192.168.184.149:82/test_group/autotest.git
> git --version # timeout=10
> git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials gitlab-auth-http
> git fetch --tags --progress http://192.168.184.149:82/test_group/autotest.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> git rev-parse refs/remotes/origin/master^{commit} # timeout=10
Checking out Revision 597072787d61638e570237f69adb11189aa92a40 (refs/remotes/origin/master)
> git config core.sparsecheckout # timeout=10
> git checkout -f 597072787d61638e570237f69adb11189aa92a40 # timeout=10
> git branch -a -v --no-abbrev # timeout=10
> git branch -D master # timeout=10
> git checkout -b master 597072787d61638e570237f69adb11189aa92a40 # timeout=10
Commit message: "update"
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (RUN)
[Pipeline] sh
+ /opt/ant/bin/ant -file build.xml run
Buildfile: /var/lib/jenkins/workspace/auto_test_pipline/build.xml
run:
test:
[jmeter] Executing test plan: /var/lib/jenkins/workspace/auto_test/01.jmx ==> /root/test_report/jtl/TestReport202207101035.jtl
[jmeter] WARNING: An illegal reflective access operation has occurred
[jmeter] WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/opt/jmeter/lib/xstream-1.4.11.jar) to field java.util.TreeMap.comparator
[jmeter] WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
[jmeter] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
[jmeter] WARNING: All illegal access operations will be denied in a future release
[jmeter] Creating summariser <summary>
[jmeter] Created the tree successfully using /var/lib/jenkins/workspace/auto_test/01.jmx
[jmeter] Starting the test @ Sun Jul 10 22:35:10 CST 2022 (1657463710315)
[jmeter] Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
[jmeter] Warning: Nashorn engine is planned to be removed from a future JDK release
[jmeter] summary = 3 in 00:00:06 = 0.5/s Avg: 5941 Min: 5928 Max: 5963 Err: 0 (0.00%)
[jmeter] Tidying up ... @ Sun Jul 10 22:35:17 CST 2022 (1657463717140)
[jmeter] ... end of run
[jmeter] Executing test plan: /var/lib/jenkins/workspace/auto_test/02.jmx ==> /root/test_report/jtl/TestReport202207101035.jtl
[jmeter] WARNING: An illegal reflective access operation has occurred
[jmeter] WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/opt/jmeter/lib/xstream-1.4.11.jar) to field java.util.TreeMap.comparator
[jmeter] WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
[jmeter] WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
[jmeter] WARNING: All illegal access operations will be denied in a future release
[jmeter] Creating summariser <summary>
[jmeter] Created the tree successfully using /var/lib/jenkins/workspace/auto_test/02.jmx
[jmeter] Starting the test @ Sun Jul 10 22:35:19 CST 2022 (1657463719567)
[jmeter] Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
[jmeter] Warning: Nashorn engine is planned to be removed from a future JDK release
[jmeter] summary = 1 in 00:00:01 = 0.9/s Avg: 839 Min: 839 Max: 839 Err: 0 (0.00%)
[jmeter] Tidying up ... @ Sun Jul 10 22:35:21 CST 2022 (1657463721231)
[jmeter] ... end of run
report:
[xslt] Processing /root/test_report/jtl/TestReport202207101035.jtl to /root/test_report/html/TestReport.html
[xslt] Loading stylesheet /opt/jmeter/extras/jmeter.results.shanhe.me.xsl
BUILD SUCCESSFUL
Total time: 14 seconds
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (format report)
[Pipeline] script
[Pipeline] {
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // stage
[Pipeline] stage
[Pipeline] { (Declarative: Post Actions)
[Pipeline] publishHTML
[htmlpublisher] Archiving HTML reports...
[htmlpublisher] Archiving at PROJECT level /root/test_report/html to /var/lib/jenkins/jobs/auto_test_pipline/htmlreports/HTML_20Report
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
第一次构建时遇到错误:
Scripts not permitted to use staticMethod java.lang.System setProperty java.lang.String java.lang.String. Administrators can decide whether to approve or reject this signature.
解决:
本文来自博客园,作者:chuangzhou,转载请注明原文链接:https://www.cnblogs.com/czzz/p/16461969.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!