I have a Jenkins Pipeline job which is configured to checkout a git repo and a specific local branch.
How can i get the name of the local branch in my Jenkinsfile?
I tried to load the git jenkins plugin env properties but had no luck.
node {
checkout scm
echo "1 "+ env.GIT_LOCAL_BRANCH
echo "2 "+ env.GIT_BRANCH
}
Both values are "null"
I found that I can capture the return value from
checkout scm
and use that to get the branch name (and other values)By defining the variable outside the node it is available in stages after the checkout.
You can use
scm
attributes to get the list of branches configured for yourscm
:I'm now using the sh call to get the branch name. This requires at least version 2.4 of the Pipeline Nodes and Processes Plugin.