fix(jenkins): add containerd cache cleanup before deploy to prevent concurrent pull corruption

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
这个提交包含在:
XuqmGroup 2026-05-23 02:48:43 +08:00
父节点 67da05dadc
当前提交 978f919e4c

19
Jenkinsfile vendored
查看文件

@ -59,9 +59,24 @@ pipeline {
withCredentials([sshUserPrivateKey(credentialsId: 'PROD_SSH_KEY', keyFileVariable: 'SSH_KEY')]) {
script {
def imageName = "${ACR_REGISTRY}/${ACR_NAMESPACE}/${params.SERVICE}:${params.IMAGE_TAG}"
retry(3) {
def remoteCmd = """
set -e
# 清理悬空镜像,避免 containerd 存储损坏
docker image prune -f 2>/dev/null || true
# 拉取镜像(失败则清理后重试)
if ! docker pull ${imageName}; then
echo 'Pull failed, cleaning containerd cache and retrying...'
docker system prune -f
docker pull ${imageName}
fi
# 部署
docker compose -f ${COMPOSE_FILE} up -d --no-deps --force-recreate ${params.SERVICE}
# 清理旧镜像
docker image prune -f
""".stripIndent()
retry(2) {
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"
ssh -i "%SSH_KEY%" -o StrictHostKeyChecking=no ${PROD_USER}@${PROD_HOST} "${remoteCmd}"
"""
}
}