如何使用Jenkins Git插件接收本地Git分支名称? [英] How to receive local Git branch name with Jenkins Git plugin?

查看:621
本文介绍了如何使用Jenkins Git插件接收本地Git分支名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Jenkins Git 插件(第2版.0)在特定分支上运行构建,例如 1.4



$ {GIT_BRANCH} 在这种情况下包含 origin / 1.4 值。

如何获得用于克隆的本地Git分支的名称只是 1.4 没有 origin / 前缀

已经尝试检出到特定的本地分支分支名称 1.4 的附加行为,但没有任何变化。



我见过相关的公关在GitHub上,但它被拒绝了(因为它只修复了一个案例,只有 origin remote)。

解决方案

您可以很容易地从变量中去掉前缀: $ {GIT_BRANCH ## origin /}



虽然这不是一个非常通用的解决方案,但它非常简单,我还没有看到Jenkins克隆的存储库,它会使用除 origin 以外的其他内容遥远的纳姆e。

更新:实际上, $ {GIT_BRANCH#* /} 任何来源,甚至包含斜线的分支。 是非贪婪glob匹配, ## 启用贪婪匹配。有关详细信息,请参阅 Bash参考手册


I am using Branch Specifier option of Jenkins Git plugin (v2.0) to run build on specific branch, e.g. 1.4.

${GIT_BRANCH} in this case contains origin/1.4 value.

How can I receive a name of the local Git branch used for cloning (i.e. just 1.4 without origin/ prefix?

I've tried Check out to specific local branch Additional Behaviour with branch name 1.4, but nothing had changed.

I've seen related PR on GitHub, but it was declined (as it fixes only one case with just origin remote).

解决方案

You can strip the prefix from the variable pretty easily: ${GIT_BRANCH##origin/}

Although this is not a very general solution, it's quite simple and I haven't seen a repository cloned by Jenkins, which would use something else than origin for the remote name.

Update: Actually, ${GIT_BRANCH#*/} will work for any origin and even for branches containing slashes. The # does non-greedy glob matching, ## enables greedy matching. See Bash Reference Manual for details.

这篇关于如何使用Jenkins Git插件接收本地Git分支名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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