What is the branch name variable for Jenkins multibranch pipelines? What is the branch name variable for Jenkins multibranch pipelines? jenkins jenkins

What is the branch name variable for Jenkins multibranch pipelines?


The env.BRANCH_NAME variable contains the branch name.

As of Pipeline Groovy Plugin 2.18, you can also just use BRANCH_NAME (env isn't required but still accepted.)


There is not a dedicated variable for this purpose yet (JENKINS-30252). In the meantime you can take advantage of the fact that the subproject name is taken from the branch name, and use

env.JOB_NAME.replaceFirst('.+/', '')

This has now been resolved, see Krzysztof KrasoĊ„'s answer.


Jenkins documentation has a list of all the env variable for your perusal here