From 4240f82f73f2e7ed61a5cf760cf279928ad15d36 Mon Sep 17 00:00:00 2001 From: Andrew Berezovskyi Date: Wed, 16 Feb 2022 01:01:43 +0100 Subject: [PATCH] another way of getting the branch name Signed-off-by: Andrew Berezovskyi --- Jenkinsfile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Jenkinsfile b/Jenkinsfile index 4a406535d..29b761848 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -4,11 +4,22 @@ pipeline { maven 'apache-maven-latest' jdk 'temurin-jdk11-latest' } + pipeline { + environment { + // https://stackoverflow.com/questions/42383273/get-git-branch-name-in-jenkins-pipeline-jenkinsfile + BRANCH_NAME_B = "${GIT_BRANCH.split("/")[1]}" + BRANCH_NAME_A = "${GIT_BRANCH.split("/").size() > 1 ? GIT_BRANCH.split("/")[1] : GIT_BRANCH}" + BRANCH_NAME = "${GIT_BRANCH.split('/').size() > 1 ? GIT_BRANCH.split('/')[1..-1].join('/') : GIT_BRANCH}" + } + } stages { stage('Debug') { steps { script { echo 'Working on' + env.BRANCH_NAME + echo '... or A' + env.BRANCH_NAME_A + echo '... or B' + env.BRANCH_NAME_B + echo 'CHANGE_BRANCH' + env.CHANGE_BRANCH } } }