Skip to content

Commit da5492a

Browse files
authored
Fallback to merge-base if commit hash is invalid
1 parent 7624823 commit da5492a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Jenkinsfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,14 @@ void checkE2EIgnoreFiles() {
315315
echo "This is the first run. Using merge base as the starting point for the diff."
316316
changedFiles = sh(script: "git diff --name-only \$(git merge-base HEAD origin/$CHANGE_TARGET)", returnStdout: true).trim().split('\n').findAll{it}
317317
} else {
318-
echo "Processing changes since last processed commit: $lastProcessedCommitHash"
319-
changedFiles = sh(script: "git diff --name-only $lastProcessedCommitHash HEAD", returnStdout: true).trim().split('\n').findAll{it}
318+
def commitExists = sh(script: "git cat-file -e $lastProcessedCommitHash 2>/dev/null", returnStatus: true) == 0
319+
if (commitExists) {
320+
echo "Processing changes since last processed commit: $lastProcessedCommitHash"
321+
changedFiles = sh(script: "git diff --name-only $lastProcessedCommitHash HEAD", returnStdout: true).trim().split('\n').findAll{it}
322+
} else {
323+
echo "Commit hash $lastProcessedCommitHash does not exist in the current repository. Using merge base as the starting point for the diff."
324+
changedFiles = sh(script: "git diff --name-only \$(git merge-base HEAD origin/$CHANGE_TARGET)", returnStdout: true).trim().split('\n').findAll{it}
325+
}
320326
}
321327

322328
echo "Excluded files: $excludedFiles"

0 commit comments

Comments
 (0)