From af922ae4202f1b623526d8789a3b05d41c04116a Mon Sep 17 00:00:00 2001 From: XuqmGroup Date: Thu, 21 May 2026 10:58:08 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=B8=B2=E8=A1=8C=E5=8C=96=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E9=83=A8=E7=BD=B2=E9=98=B2=E6=AD=A2=E5=B9=B6=E5=8F=91?= =?UTF-8?q?=20docker=20pull=20=E7=AB=9E=E4=BA=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 多服务同时构建时 Deploy 阶段并发向同一台生产机 docker pull, containerd content store 写入共享 layer 产生文件竞争导致 rename 失败。 加 lock('prod-deploy') 确保所有服务按序部署,并加 retry(3) 容忍偶发抖动。 Co-Authored-By: Claude Sonnet 4.6 --- Jenkinsfile | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 97559be..ca81d00 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -55,12 +55,16 @@ pipeline { stage('Deploy to Production') { when { expression { return params.DEPLOY } } steps { - withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { - script { - def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${params.SERVICE}:${params.IMAGE_TAG}" - bat """ - ssh -i "%SSH_KEY%" -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} "docker pull ${imageName} && docker compose -f ${COMPOSE_FILE} up -d --no-deps --force-recreate ${params.SERVICE} && docker image prune -f" - """ + lock('prod-deploy') { + withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) { + script { + def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${params.SERVICE}:${params.IMAGE_TAG}" + retry(3) { + bat """ + ssh -i "%SSH_KEY%" -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} "docker pull ${imageName} && docker compose -f ${COMPOSE_FILE} up -d --no-deps --force-recreate ${params.SERVICE} && docker image prune -f" + """ + } + } } } }