fix: clean Jenkinsfile (single-quote sh blocks)

This commit is contained in:
xiangning 2026-07-03 17:37:02 +08:00
parent 2a228407c3
commit d4275c767d

31
Jenkinsfile vendored
View File

@ -1,6 +1,5 @@
// BuildFlow buildflow-portal CI/CD // BuildFlow buildflow-portal CI/CD - clean version
// ①拉取代码 -> ②编译打包 -> 推送Harbor -> ③部署 // ①拉取代码 -> ②编译打包 -> 推送Harbor -> ③部署 + 飞书通知
// 飞书卡片通知(成功绿/失败红)
def feishuNotify = { String result, String failedStageName = "" -> def feishuNotify = { String result, String failedStageName = "" ->
def dur = currentBuild.durationString.replace(" and counting", "") def dur = currentBuild.durationString.replace(" and counting", "")
@ -28,8 +27,8 @@ def feishuNotify = { String result, String failedStageName = "" ->
def card = [msg_type: "interactive", card: [header: [title: [tag: "plain_text", content: title], template: color], elements: elements]] def card = [msg_type: "interactive", card: [header: [title: [tag: "plain_text", content: title], template: color], elements: elements]]
def jsonStr = groovy.json.JsonOutput.toJson(card) def jsonStr = groovy.json.JsonOutput.toJson(card)
writeFile file: "/tmp/feishu_msg.json", text: jsonStr writeFile file: "/tmp/feishu_msg.json", text: jsonStr
sh "curl -sS -X POST https://open.feishu.cn/open-apis/bot/v2/hook/d215e8ed-edea-4f07-a77c-2a0e5b52d9b9 -H 'Content-Type: application/json' -d @/tmp/feishu_msg.json || true" sh 'curl -sS -X POST https://open.feishu.cn/open-apis/bot/v2/hook/d215e8ed-edea-4f07-a77c-2a0e5b52d9b9 -H "Content-Type: application/json" -d @/tmp/feishu_msg.json || true'
sh "rm -f /tmp/feishu_msg.json" sh 'rm -f /tmp/feishu_msg.json'
} }
pipeline { pipeline {
@ -59,12 +58,12 @@ pipeline {
stage("推送 Harbor") { stage("推送 Harbor") {
steps { steps {
withCredentials([usernamePassword(credentialsId: "harbor-credentials", usernameVariable: "HUSER", passwordVariable: "HPASS")]) { withCredentials([usernamePassword(credentialsId: "harbor-credentials", usernameVariable: "HUSER", passwordVariable: "HPASS")]) {
sh """ sh '''
echo \$HPASS | docker login ${HARBOR} -u \$HUSER --password-stdin echo $HPASS | docker login $HARBOR -u $HUSER --password-stdin
docker push ${IMAGE}:${TAG} docker push $IMAGE:$TAG
docker push ${IMAGE}:latest docker push $IMAGE:latest
docker logout ${HARBOR} docker logout $HARBOR
""" '''
} }
} }
} }
@ -73,11 +72,11 @@ pipeline {
script { script {
try { try {
node("deploy-agent") { node("deploy-agent") {
sh """ sh '''
docker pull ${IMAGE}:latest docker pull $IMAGE:latest
docker rm -f buildflow-portal 2>/dev/null || true docker rm -f buildflow-portal 2>/dev/null || true
docker run -d --name buildflow-portal --restart unless-stopped -p 5174:5173 ${IMAGE}:latest docker run -d --name buildflow-portal --restart unless-stopped -p 5174:5173 $IMAGE:latest
""" '''
} }
echo "部署完成" echo "部署完成"
} catch (e) { } catch (e) {
@ -99,4 +98,4 @@ pipeline {
deleteDir() deleteDir()
} }
} }
} }