Skip to content

Commit

Permalink
another way of getting the branch name
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Berezovskyi <andriib@kth.se>
  • Loading branch information
berezovskyi committed Feb 16, 2022
1 parent c7e83c9 commit 4240f82
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 4240f82

Please sign in to comment.