|
|
@@ -16,9 +16,13 @@ def normalizeGitBranch(String raw) {
|
|
|
if (!b) {
|
|
|
return 'uat-20260202'
|
|
|
}
|
|
|
- b = b.replaceFirst('^refs/heads/', '')
|
|
|
- b = b.replaceFirst('^origin/', '')
|
|
|
- return b
|
|
|
+ while (b.startsWith('refs/heads/')) {
|
|
|
+ b = b.substring('refs/heads/'.length())
|
|
|
+ }
|
|
|
+ while (b.startsWith('origin/')) {
|
|
|
+ b = b.substring('origin/'.length())
|
|
|
+ }
|
|
|
+ return b ?: 'uat-20260202'
|
|
|
}
|
|
|
|
|
|
/** HARBOR_PUSH_SCOPE: all-java-services | <repo>-only */
|
|
|
@@ -172,7 +176,7 @@ pipeline {
|
|
|
name: 'GIT_BRANCH',
|
|
|
defaultValue: 'uat-20260202',
|
|
|
trim: true,
|
|
|
- description: 'Git branch, must match remote (e.g. uat-20260202)'
|
|
|
+ description: 'Git branch name only (e.g. uat-20260202). Do not prefix origin/'
|
|
|
)
|
|
|
booleanParam(name: 'FORCE_UPDATE', defaultValue: false, description: 'mvn -U (routine builds leave unchecked for speed)')
|
|
|
booleanParam(name: 'ALLOW_SNAPSHOTS', defaultValue: true, description: 'allow SNAPSHOT deps')
|
|
|
@@ -227,19 +231,20 @@ pipeline {
|
|
|
stage('Checkout') {
|
|
|
steps {
|
|
|
script {
|
|
|
+ // Do not use env.GIT_BRANCH — Jenkins SCM plugin injects origin/<branch> and overwrites it.
|
|
|
def branch = normalizeGitBranch(params.GIT_BRANCH)
|
|
|
if (!branch) {
|
|
|
error('GIT_BRANCH is required')
|
|
|
}
|
|
|
- env.GIT_BRANCH = branch
|
|
|
- echo ">>> Checkout branch: ${env.GIT_BRANCH} (use branch name only, e.g. uat-20260202)"
|
|
|
- git branch: "${env.GIT_BRANCH}",
|
|
|
- credentialsId: "${env.GIT_CREDENTIALS}",
|
|
|
- url: "${env.GIT_URL}"
|
|
|
+ env.UAT_GIT_BRANCH = branch
|
|
|
+ if (params.GIT_BRANCH?.trim() != branch) {
|
|
|
+ echo ">>> GIT_BRANCH normalized: '${params.GIT_BRANCH}' -> '${branch}'"
|
|
|
+ }
|
|
|
+ echo ">>> Checkout branch: ${branch}"
|
|
|
sh """
|
|
|
set -e
|
|
|
git fetch origin
|
|
|
- git reset --hard origin/${env.GIT_BRANCH}
|
|
|
+ git checkout -B ${branch} origin/${branch}
|
|
|
git log -1 --oneline
|
|
|
"""
|
|
|
}
|