mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Merge pull request #29540 from overleaf/gs-jenkins-pr-build-tags-remote
Check if Jenkins checkout revision exists on remote GitOrigin-RevId: cb110f5479836ccbfd1a62f501210dee6606d37e
This commit is contained in:
Vendored
+15
-3
@@ -30,9 +30,21 @@ pipeline {
|
||||
script {
|
||||
def relevantCommitHash
|
||||
if (env.CHANGE_BRANCH) {
|
||||
echo "PR build detected. Jenkins checked out a merge commit: ${GIT_COMMIT}"
|
||||
relevantCommitHash = sh(script: 'git rev-parse HEAD^1', returnStdout: true).trim()
|
||||
echo "Found actual branch commit: ${relevantCommitHash}"
|
||||
def commitExistsOnRemote = sh(script: "git branch --remotes --contains ${GIT_COMMIT}", returnStdout: true).trim()
|
||||
if (commitExistsOnRemote) {
|
||||
echo "PR build detected, but commit exists on remote. Using ${GIT_COMMIT}"
|
||||
relevantCommitHash = "${GIT_COMMIT}"
|
||||
} else {
|
||||
def parentCommits = sh(script: 'git rev-parse HEAD^@', returnStdout: true).trim().split('\n')
|
||||
if (parentCommits.size() >= 2) {
|
||||
echo "PR build detected. Jenkins checked out a merge commit: ${GIT_COMMIT} (parents: ${parentCommits.join(', ')})"
|
||||
relevantCommitHash = parentCommits[0]
|
||||
echo "Using first parent (branch commit): ${relevantCommitHash}"
|
||||
} else {
|
||||
echo "WARN: PR build detected, but ${GIT_COMMIT} is neither a merge commit, nor does it exist on the remote."
|
||||
relevantCommitHash = "${GIT_COMMIT}"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
echo "Branch build detected. Using commit: ${GIT_COMMIT}"
|
||||
relevantCommitHash = "${GIT_COMMIT}"
|
||||
|
||||
Reference in New Issue
Block a user