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()