Jenkins Multibranch pipeline: What is the branch name variable?

折月煮酒 提交于 2019-11-29 00:53:27
Krzysztof Krasoń

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.)

Jesse Glick

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.

jus4kikz

I found this stackoverflow post example useful: Git Variables in Jenkins Workflow plugin

sh '//...
    git rev-parse --abbrev-ref HEAD > GIT_BRANCH'
    git_branch = readFile('GIT_BRANCH').trim()
    echo git_branch
    //...
   '
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!