From e4d07a530656a7853f3d68455d49128d87fbfe2b Mon Sep 17 00:00:00 2001 From: lzh Date: Thu, 22 Jan 2026 10:30:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=20commit?= =?UTF-8?q?=20=E5=9C=BA=E6=99=AF=E4=B8=8B=E6=9C=8D=E5=8A=A1=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E6=A3=80=E6=B5=8B=E9=81=97=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原 getChangedFiles() 只对比 HEAD~1 和 HEAD,导致一次 push 多个 commits 时只会检测最新一个 commit 的变更。 修改为使用 GIT_PREVIOUS_SUCCESSFUL_COMMIT(Jenkins 内置变量,上次 成功构建的 commit)作为基准,确保所有变更文件都能被正确检测。 Co-Authored-By: Claude Opus 4.5 --- Jenkinsfile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 46536a2..0947196 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -435,12 +435,23 @@ pipeline { // 辅助函数 // ============================================ -// 获取变更的文件列表 +// 获取变更的文件列表(对比上次成功构建,支持多 commit) def getChangedFiles() { def changedFiles = sh( script: ''' - PREV=$(git rev-parse HEAD~1 2>/dev/null || echo "") - [ -z "$PREV" ] && echo "all" || git diff --name-only $PREV HEAD + # 优先使用上次成功构建的 commit + if [ -n "$GIT_PREVIOUS_SUCCESSFUL_COMMIT" ]; then + PREV="$GIT_PREVIOUS_SUCCESSFUL_COMMIT" + else + # 回退到 origin/master(如果有) + PREV=$(git rev-parse origin/master 2>/dev/null || git rev-parse HEAD~1 2>/dev/null || echo "") + fi + + if [ -z "$PREV" ]; then + echo "all" + else + git diff --name-only $PREV HEAD + fi ''', returnStdout: true ).trim()