Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
chenjing
/
api-test
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
b28ebabe
...
b28ebabef7b8676e800ed594984f70278f9adeff
authored
2026-01-22 11:40:13 +0800
by
chenjing
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修复:使用Jenkins BUILD_URL生成正确的报告链接
1 parent
e012e8a0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
13 deletions
Jenkinsfile
api_cases.xlsx
send_wecom_notification.py
Jenkinsfile
View file @
b28ebab
...
...
@@ -56,6 +56,8 @@ pipeline {
env.IP_HOST = ipHost
echo "IP_HOST: ${env.IP_HOST}"
}
// 使用 catchError 让测试失败时也继续执行后续阶段
catchError(buildResult: 'FAILURE', stageResult: 'UNSTABLE') {
sh '''
. venv/bin/activate
export DEPLOY_ENV="${DEPLOY_ENV}"
...
...
@@ -66,13 +68,18 @@ pipeline {
'''
}
}
}
stage('生成报告') {
steps {
echo "正在生成测试报告..."
sh '''
echo "查找报告文件..."
ls -lh reports/${DEPLOY_ENV}/ 2>/dev/null || echo "未找到报告文件"
if [ -d "reports/${DEPLOY_ENV}" ]; then
ls -lh reports/${DEPLOY_ENV}/
else
echo "未找到报告目录: reports/${DEPLOY_ENV}/"
fi
'''
}
}
...
...
@@ -82,6 +89,16 @@ pipeline {
always {
echo "正在收集测试结果..."
// 调试信息:打印环境变量
sh '''
echo "=== Jenkins 环境变量调试信息 ==="
echo "JENKINS_URL: ${JENKINS_URL}"
echo "JOB_NAME: ${JOB_NAME}"
echo "BUILD_NUMBER: ${BUILD_NUMBER}"
echo "BUILD_URL: ${BUILD_URL}"
echo "==============================="
'''
// 列出所有报告文件(调试用)
sh '''
echo "=== 报告文件清单 ==="
...
...
api_cases.xlsx
View file @
b28ebab
No preview for this file type
send_wecom_notification.py
View file @
b28ebab
...
...
@@ -7,10 +7,11 @@
import
requests
import
json
import
sys
import
re
from
datetime
import
datetime
import
os
def
send_wecom_notification
(
webhook_url
,
env_name
,
build_status
,
build_
number
,
job_name
,
jenkins_
url
):
def
send_wecom_notification
(
webhook_url
,
env_name
,
build_status
,
build_url
):
"""
发送企微群通知
...
...
@@ -18,13 +19,15 @@ def send_wecom_notification(webhook_url, env_name, build_status, build_number, j
webhook_url: 企微群webhook URL
env_name: 运行环境 (test/uat/prod)
build_status: 构建状态 ('success' 或 'failure')
build_number: Jenkins构建号
job_name: Jenkins任务名称
jenkins_url: Jenkins服务器地址
build_url: Jenkins完整的构建URL (格式: http://jenkins/job/xxx/123/)
"""
# 构建报告链接
report_url
=
f
"{jenkins_url}/job/{job_name}/{build_number}/artifact/reports/{env_name}/"
# 构建报告链接 - BUILD_URL通常以/结尾,直接拼接
report_url
=
f
"{build_url}artifact/reports/{env_name}/"
# 从BUILD_URL中提取构建号 (格式: http://jenkins/.../123/)
match
=
re
.
search
(
r'/(\d+)/?$'
,
build_url
.
rstrip
(
'/'
))
build_number
=
match
.
group
(
1
)
if
match
else
'unknown'
# 根据状态构建消息
if
build_status
==
'success'
:
...
...
@@ -97,23 +100,23 @@ if __name__ == "__main__":
webhook_url
=
os
.
getenv
(
'WECOM_WEBHOOK_URL'
)
env_name
=
os
.
getenv
(
'DEPLOY_ENV'
,
'test'
)
build_status
=
os
.
getenv
(
'BUILD_STATUS'
,
'success'
)
build_number
=
os
.
getenv
(
'BUILD_NUMBER'
,
'unknown'
)
job_name
=
os
.
getenv
(
'JOB_NAME'
,
'api_test'
)
jenkins_url
=
os
.
getenv
(
'JENKINS_URL'
,
''
)
.
rstrip
(
'/'
)
or
'http://localhost:8080'
build_url
=
os
.
getenv
(
'BUILD_URL'
)
# 验证必需参数
if
not
webhook_url
:
print
(
"❌ 错误: 未设置 WECOM_WEBHOOK_URL 环境变量"
)
sys
.
exit
(
1
)
if
not
build_url
:
print
(
"❌ 错误: 未设置 BUILD_URL 环境变量"
)
sys
.
exit
(
1
)
# 发送通知
success
=
send_wecom_notification
(
webhook_url
=
webhook_url
,
env_name
=
env_name
,
build_status
=
build_status
,
build_number
=
build_number
,
job_name
=
job_name
,
jenkins_url
=
jenkins_url
build_url
=
build_url
)
# 返回退出码
...
...
Please
register
or
sign in
to post a comment