fix: use BRANCH_NAME env var for proper branch detection in Jenkins

git rev-parse --abbrev-ref HEAD returns 'HEAD' in detached HEAD mode (Jenkins checkout).
Use BRANCH_NAME (Multibranch Pipeline) or GIT_BRANCH as fallback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
soufiane 2025-12-05 16:27:42 +01:00
parent d4333ee300
commit 96622b9c4c

4
Jenkinsfile vendored
View File

@ -68,7 +68,9 @@ pipeline {
stage('🧭 Init - Détection environnement') {
steps {
script {
def currentBranch = sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim()
// Utiliser BRANCH_NAME (Multibranch Pipeline) ou GIT_BRANCH (fallback)
// git rev-parse --abbrev-ref HEAD retourne "HEAD" en detached HEAD mode
def currentBranch = env.BRANCH_NAME ?: env.GIT_BRANCH?.replaceAll('origin/', '') ?: sh(script: "git rev-parse --abbrev-ref HEAD", returnStdout: true).trim()
echo "🧭 Branche détectée : ${currentBranch}"
if (["dev", "preprod", "main"].contains(currentBranch)) {