Issue
How to set branch name in variable in Jenkins Pipeline job? I have Jenins pipeline below which returns null in BRANCH_NAME
node{
def BRANCH_NAME = env.BRANCH_NAME
echo BRANCH_NAME
}
Solution
To get branch name through env.BRANCH_NAME
, your pipeline need to be Multiple Branch Pipeline.
BRANCH_NAME
For a multibranch project, this will be set to the name of the branch being built,
for example in case you wish to deploy to production from
master but not from feature branches;
if corresponding to some kind of change request, the name is generally arbitrary
(refer to CHANGE_ID and CHANGE_TARGET).
Answered By - yong
Answer Checked By - Terry (JavaFixing Volunteer)