Jenkins管道分支名称返回null [英] Jenkins pipeline branch name returns null

查看:472
本文介绍了Jenkins管道分支名称返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为jenkins groovy脚本获取分支的名称.我无法获取当前的分支名称.我尝试以下方法:

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}"

这里是输出-它始终返回null.

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

我想念什么吗?

推荐答案

此变量仅在多分支管线中起作用:

This variable only works in a multibranch pipline:

BRANCH_NAME 对于多分支项目,此名称将设置为正在构建的分支的名称,例如,如果您希望从主分支而不是功能分支部署到生产环境.

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

这篇关于Jenkins管道分支名称返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆