fix(ci): 修复多 commit 场景下服务构建检测遗漏
原 getChangedFiles() 只对比 HEAD~1 和 HEAD,导致一次 push 多个 commits 时只会检测最新一个 commit 的变更。 修改为使用 GIT_PREVIOUS_SUCCESSFUL_COMMIT(Jenkins 内置变量,上次 成功构建的 commit)作为基准,确保所有变更文件都能被正确检测。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
17
Jenkinsfile
vendored
17
Jenkinsfile
vendored
@@ -435,12 +435,23 @@ pipeline {
|
|||||||
// 辅助函数
|
// 辅助函数
|
||||||
// ============================================
|
// ============================================
|
||||||
|
|
||||||
// 获取变更的文件列表
|
// 获取变更的文件列表(对比上次成功构建,支持多 commit)
|
||||||
def getChangedFiles() {
|
def getChangedFiles() {
|
||||||
def changedFiles = sh(
|
def changedFiles = sh(
|
||||||
script: '''
|
script: '''
|
||||||
PREV=$(git rev-parse HEAD~1 2>/dev/null || echo "")
|
# 优先使用上次成功构建的 commit
|
||||||
[ -z "$PREV" ] && echo "all" || git diff --name-only $PREV HEAD
|
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
|
returnStdout: true
|
||||||
).trim()
|
).trim()
|
||||||
|
|||||||
Reference in New Issue
Block a user