Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins pipeline branch name returns null

Tags:

I'm trying to get the name of my branch for a jenkins groovy script. I cannot get the current branch name. I try the following:

stage('Check out code') checkout scm echo "My branch is: ${env.BRANCH_NAME}" 

Here is the output - it always returns null.

 Checking out Revision 33b531b2f1caaf8b64d968e437306f39d2dba1da   (origin/pipeline)   > git.exe config core.sparsecheckout # timeout=10   > git.exe checkout -f 33b531b2f1caaf8b64d968e437306f39d2dba1da  [Pipeline] echo  My branch is: null 

Am I missing something?

like image 545
pogorman Avatar asked May 03 '17 21:05

pogorman


1 Answers

This variable only works in a multibranch pipline:

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.

I was testing in a normal pipline

like image 165
pogorman Avatar answered Oct 04 '22 02:10

pogorman