From c487c80513b444ab226f3c963daf13d24c44e177 Mon Sep 17 00:00:00 2001 From: dxin Date: Sat, 8 Nov 2025 20:17:18 +0800 Subject: [PATCH] 1 --- SCM/s1_go_lessie_api.groovy | 11 +++++++---- SCM/s1_python_lessie_agents.groovy | 8 +++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/SCM/s1_go_lessie_api.groovy b/SCM/s1_go_lessie_api.groovy index c53968b..c366ff4 100644 --- a/SCM/s1_go_lessie_api.groovy +++ b/SCM/s1_go_lessie_api.groovy @@ -242,7 +242,7 @@ pipeline { def imagePrefix = "${REGISTRY}/${NAMESPACE}/${IMAGE_NAME}" // 获取所有镜像(按创建时间排序,越新的越前) - def allImagesRaw = sh(script: "docker images ${imagePrefix} --format '{{.Repository}}:{{.Tag}} {{.CreatedAt}}' | sort -rk2", returnStdout: true).trim() + def allImagesRaw = sh(script: "docker images ${imagePrefix} --format '{{.ID}} {{.Repository}}:{{.Tag}}' | sort -rk1", returnStdout: true).trim() if (!allImagesRaw) { echo "未找到任何镜像,无需清理" return @@ -258,9 +258,11 @@ pipeline { echo "发现 ${oldImages.size()} 个旧镜像需要清理" oldImages.each { line -> - def imageTag = line.split(' ')[0] - echo "删除旧镜像: ${imageTag}" - sh(returnStatus: true, script: "docker rmi -f \"${imageTag}\" || true") + def parts = line.split(' ') + def imageId = parts[0] + def imageTag = parts[1] + echo "删除旧镜像: ${imageTag} (ID: ${imageId})" + sh "docker rmi -f \"${imageId}"\ || true" } echo "清理完成,当前镜像状态:" @@ -282,5 +284,6 @@ pipeline { // 输出构建结果 echo "部署有错误,请检查!" } + } } \ No newline at end of file diff --git a/SCM/s1_python_lessie_agents.groovy b/SCM/s1_python_lessie_agents.groovy index ecdb1bf..b8a114b 100644 --- a/SCM/s1_python_lessie_agents.groovy +++ b/SCM/s1_python_lessie_agents.groovy @@ -238,9 +238,11 @@ pipeline { echo "发现 ${oldImages.size()} 个旧镜像需要清理" oldImages.each { line -> - def imageTag = line.split(' ')[0] - echo "删除旧镜像: ${imageTag}" - sh(returnStatus: true, script: "docker rmi -f \"${imageTag}\" || true") + def parts = line.split(' ') + def imageId = parts[0] + def imageTag = parts[1] + echo "删除旧镜像: ${imageTag} (ID: ${imageId})" + sh "docker rmi -f \"${imageId}"\ || true" } echo "清理完成,当前镜像状态:"