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:59 +01:00
parent f348918b79
commit a419a9f42a

4
Jenkinsfile vendored
View File

@ -67,7 +67,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)) {