From 50eb60b895ed73fcf7e2cadc5131adafffa2c265 Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Thu, 11 Jun 2026 15:16:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E9=83=A8=E7=BD=B2=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E5=8A=A0=20lock(prod-deploy)=20=E5=92=8C=20retry=EF=BC=8C?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=B9=B6=E5=8F=91=20pull=20=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多个 Jenkins job 同时向同一服务器执行 docker pull 时,containerd ingest 目录存在 rename 竞争,会出现 "no such file or directory" 错误。通过全局锁 prod-deploy 序列化所有部署操作(与 Server Jenkinsfile 共享同一锁名),并加 retry(2) 兜底。 Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 51d3a30..bc84972 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -83,12 +83,16 @@ pipeline { stage('Deploy to Production') { when { expression { return params.DEPLOY } } steps { - withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { - script { - def fullImage = "${env.ACR_REGISTRY}/${env.ACR_NAMESPACE}/${env.IMAGE_NAME}:${params.IMAGE_TAG}" - bat """ - ssh -i "%SSH_KEY%" -o StrictHostKeyChecking=no ${env.PROD_USER}@${env.PROD_HOST} "docker rm -f xuqm-${env.DEPLOY_SERVICE} 2>/dev/null || true; docker pull ${fullImage} || exit 1; docker compose -f ${env.COMPOSE_FILE} up -d --no-deps --force-recreate ${env.DEPLOY_SERVICE} || exit 1; docker image prune -f" - """ + lock('prod-deploy') { + withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { + script { + def fullImage = "${env.ACR_REGISTRY}/${env.ACR_NAMESPACE}/${env.IMAGE_NAME}:${params.IMAGE_TAG}" + retry(2) { + bat """ + ssh -i "%SSH_KEY%" -o StrictHostKeyChecking=no ${env.PROD_USER}@${env.PROD_HOST} "docker image prune -f 2>/dev/null || true; docker pull ${fullImage} || exit 1; docker compose -f ${env.COMPOSE_FILE} up -d --no-deps --force-recreate ${env.DEPLOY_SERVICE} || exit 1; docker image prune -f" + """ + } + } } } }