Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
cpas6-install
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李金钢
cpas6-install
Commits
a26bdf73
Commit
a26bdf73
authored
Mar 09, 2026
by
李金钢
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parents
Pipeline
#289
canceled with stages
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
284 additions
and
0 deletions
+284
-0
Jenkinsfile
Jenkinsfile
+284
-0
No files found.
Jenkinsfile
0 → 100644
View file @
a26bdf73
// 新增带返回值的跨平台 PowerShell 执行函数
def
runPowerShellWithOutput
(
script
)
{
try
{
if
(
isUnix
())
{
return
sh
(
script:
"pwsh -Command \"${script}\""
,
returnStdout:
true
).
trim
()
}
else
{
return
powershell
(
script:
script
,
returnStdout:
true
).
trim
()
}
}
catch
(
Exception
e
)
{
echo
"执行 PowerShell 脚本失败: ${e.message}"
throw
e
}
}
// properties([
// pipelineTriggers([
// // 使用 Cron 表达式,实现极其精准的控制
// // 例如:每 2 分钟扫描一次分支变动
// // parameterizedCron('H/2 * * * *'),
// // 或者使用特定的扫描触发器
// // 这里的 '2' 代表分钟,你可以随意改成任何数字
// cron('H/1 * * * *')
// ])
// ])
pipeline
{
// 全局变量定义 // 变量名 = "值" (中间不要有空行或乱放的注释)
// environment {
// GIT_EXE = 'D:\\Git\\bin\\git.exe'
// NODE_HOME = 'C:\\Program Files\\nodejs'
// }
agent
{
label
'ljgWinMachine'
// 动态匹配 ops 环境
}
parameters
{
string
(
name:
'appConfigName'
,
defaultValue:
'dehao'
,
description:
'Description for appConfigName'
)
string
(
name:
'SysName'
,
defaultValue:
'operation_platform'
,
description:
'Description for SysName:operation_platform,report_tool '
)
string
(
name:
'webapps'
,
defaultValue:
'unknown'
,
description:
'Description for audit webapps'
)
string
(
name:
'avg'
,
defaultValue:
'report'
,
description:
'Description for npm run build:avg 参数'
)
}
stages
{
stage
(
'环境排查'
)
{
steps
{
script
{
try
{
// 1. 打印 Jenkins 内部变量
echo
"--- Jenkins 内部变量 ---"
// runPowerShellWithOutput("set")
// 3. 检查 Git 版本
echo
"--- Git 版本检查 ---"
runPowerShellWithOutput
(
"git --version"
)
// 4. 检查 Node.js 版本
echo
"--- Node.js 版本检查 ---"
runPowerShellWithOutput
(
"node --version"
)
// 5. 检查 npm 版本
echo
"--- npm 版本检查 ---"
runPowerShellWithOutput
(
"npm --version"
)
}
catch
(
Exception
e
)
{
echo
"环境排查阶段发生错误: ${e.message}"
}
}
}
}
stage
(
'AI 自动决策中心'
)
{
steps
{
script
{
try
{
// 基础信息准备
def
commitId
=
env
.
GIT_COMMIT
?:
"未知Commit"
// 优先使用 env.GIT_COMMIT 获取最新的 Commit ID 和相关信息
def
actionType
=
"SKIP"
// 默认不执行
echo
"cpasBusiness: ${params.webapps}"
// --- 优先级 1: 检查 Tag ---
// 1. 自动识别是 Tag 还是 分支 //
if
(
env
.
TAG_NAME
)
{
echo
"检测到发布标签: ${env.TAG_NAME},准备打包正式版镜像..."
// 执行构建逻辑
actionType
=
"TAG_RELEASE"
// runPowerShellWithOutput("node ./scripts/build.js --cpasBusiness ${params.cpasBusiness} --framework ${params.framework} --cpasUi ${params.cpasUi} --avg ${params.avg} --commitId ${commitId}")
}
// --- 优先级 2: 检查 Commit Message ---
else
{
// 2. 抓取 Commit 信息(使用跨平台方式)
def
commitMsg
=
""
try
{
commitMsg
=
runPowerShellWithOutput
(
'git log -1 --pretty=%B'
)
}
catch
(
Exception
e
)
{
echo
"AI 自动决策中心发生错误: ${e.message}"
// 如果 PowerShell 失败,尝试直接使用 git 命令
// commitMsg = runPowerShellWithOutput("git log -1 --pretty=%B")
}
if
(
commitMsg
.
contains
(
"[deploy]"
))
{
echo
"🚀 [高优先级] 检测到 [deploy] 关键字,执行强制构建..."
actionType
=
"FORCE_DEPLOY"
}
// --- 优先级 3: 检查分支 ---
// --- 优先级 3: Release 分支判断 (正则匹配 release/*) ---
// 使用 ==~ 进行全匹配,或者 .startsWith()
else
if
(
env
.
BRANCH_NAME
==~
/release.*/
)
{
echo
"🛡️ 检测到发布分支: ${env.BRANCH_NAME},准备进行预发布构建..."
actionType
=
"PRE_RELEASE"
}
// --- 优先级 4: 常规核心分支 ---
else
if
(
env
.
BRANCH_NAME
==
'master'
||
env
.
BRANCH_NAME
==
'feat-report-zxh-bghd'
)
{
actionType
=
"REGULAR_BUILD"
}
}
// --- 统一执行中心 ---
if
(
actionType
!=
"SKIP"
)
{
echo
"决策结论: 执行模式 -> ${actionType}"
def
buildParams
=
""
if
(
params
.
appConfigName
)
{
buildParams
+=
" --appConfigName=${params.appConfigName}"
}
if
(
params
.
SysName
)
{
buildParams
+=
" --SysName=${params.SysName}"
}
if
(
params
.
avg
)
{
buildParams
+=
" --avg=${params.avg}"
}
// 执行你的 Node.js 构建脚本
// 注意:${params.xxx} 建议加上 trim() 防止空格报错
// 处理 webapps 参数并执行 S3 下载
if
(
params
.
webapps
!=
"unknown"
)
{
echo
"检测到 webapps 参数: ${params.webapps},准备执行 S3 下载..."
// 构建参数字符串
buildParams
+=
"--webapps=${params.webapps}"
echo
"执行构建参数: ${buildParams}"
// 执行 AI 构建脚本
def
buildResult
=
runPowerShellWithOutput
(
"node ./BuildScripts/ai-build.js ${buildParams}"
)
echo
"AI 构建脚本执行结果: ${buildResult}"
}
else
{
echo
"webapps 参数为默认值,跳过 S3 下载"
def
buildResult
=
runPowerShellWithOutput
(
"node ./BuildScripts/ai-build.js ${buildParams}"
)
echo
"AI 构建脚本执行结果: ${buildResult}"
}
}
else
{
echo
"⏹️ 决策结论: 无需构建,正在跳过..."
currentBuild
.
result
=
'SUCCESS'
}
}
catch
(
Exception
e
)
{
echo
"AI 自动决策中心发生错误: ${e.message}"
currentBuild
.
result
=
'FAILURE'
}
}
// 执行下游项目
}
}
}
post
{
always
{
script
{
try
{
// 优先使用 env.GIT_COMMIT 获取最新的 Commit ID 和相关信息
def
commitId
=
env
.
GIT_COMMIT
?:
"未知Commit"
// 基于 commitId 获取详细的 Git 信息
def
author
=
""
def
msg
=
""
def
lastAuthorEmail
=
""
try
{
if
(
commitId
!=
"未知Commit"
)
{
// 使用 commitId 精确获取信息,更加可靠
author
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%an"
)
msg
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%B"
)
lastAuthorEmail
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%ae"
)
}
else
{
// fallback 方案
author
=
runPowerShellWithOutput
(
"git log -1 --pretty=%an"
)
msg
=
runPowerShellWithOutput
(
"git log -1 --pretty=%B"
)
lastAuthorEmail
=
runPowerShellWithOutput
(
"git log -1 --pretty=%ae"
)
}
}
catch
(
Exception
e
)
{
// 如果 PowerShell 方式失败,使用基础 git 命令
echo
"PowerShell 方式获取 Git 信息失败,尝试基础命令: ${e.message}"
try
{
if
(
commitId
!=
"未知Commit"
)
{
author
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%an"
)
msg
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%B"
)
lastAuthorEmail
=
runPowerShellWithOutput
(
"git log -1 ${commitId} --pretty=%ae"
)
}
else
{
author
=
runPowerShellWithOutput
(
"git log -1 --pretty=%an"
)
msg
=
runPowerShellWithOutput
(
"git log -1 --pretty=%B"
)
lastAuthorEmail
=
runPowerShellWithOutput
(
"git log -1 --pretty=%ae"
)
}
}
catch
(
Exception
e2
)
{
echo
"基础 Git 命令也失败: ${e2.message}"
author
=
"未知提交人"
msg
=
"无法获取提交信息"
lastAuthorEmail
=
"unknown@example.com"
}
}
// 使用 matcher 对象进行匹配
def
matcher
=
(
msg
=~
/#[0-9]+/
)
// 安全提取:只有匹配到了才取 [0],否则赋默认值
def
bugId
=
matcher
?
matcher
[
0
]
:
"未关联Bug"
echo
"--- 自动决策中心报告 ---"
echo
"提交信息: ${msg}"
echo
"关联任务: ${bugId}"
echo
"修复人员: ${author} (${lastAuthorEmail})"
// 智能化逻辑:如果是修复 Bug,可以触发特定的通知
if
(
bugId
!=
"未关联Bug"
)
{
echo
"检测到 Bug 修复任务,准备执行回归测试..."
}
// 使用dingtalk插件提供的指令,Cpas6Package 是你在系统设置里定义的 ID,(这个一定不能改重要)
dingtalk
(
robot:
'Cpas6Package'
,
type:
'MARKDOWN'
,
title:
"AI 训练任务状态"
,
text:
[
"### 构建报告: ${env.JOB_NAME}"
,
"---"
,
"🎉 修复喜报!"
,
"修复人: ${lastAuthorEmail}"
,
"关联Bug: ${bugId}"
,
"- **当前分支**: ${env.BRANCH_NAME}"
,
"- **Commit ID**: ${commitId}"
,
"- **结果**: ${currentBuild.currentResult}"
,
"- **提交人**: ${author}"
,
"- **提交信息**: ${msg}"
,
"- **查看详情**: [点击跳转](${env.BUILD_URL})"
]
// 移除 @ 特定测试人员的逻辑
)
}
catch
(
Exception
e
)
{
echo
"获取 Git 信息时发生错误: ${e.message}"
// 错误情况下的兜底方案
dingtalk
(
robot:
'Cpas6Package'
,
type:
'MARKDOWN'
,
title:
"AI 训练任务状态"
,
text:
[
"### 构建报告: ${env.JOB_NAME}"
,
"---"
,
"⚠️ 获取 Git 信息失败"
,
"- **当前分支**: ${env.BRANCH_NAME}"
,
"- **结果**: ${currentBuild.currentResult}"
,
"- **查看详情**: [点击跳转](${env.BUILD_URL})"
]
)
}
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment