Jenkins多分支管道的分支名称变量是什么? [英] What is the branch name variable for Jenkins multibranch pipelines?

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

问题描述

我需要知道我的Jenkins多分支管道中正在构建哪个分支,以便其正确运行步骤.

I need to know which branch is being built in my Jenkins multibranch pipeline in order for it to run steps correctly.

我们正在使用具有devreleasemaster分支的gitflow模式,所有这些分支均用于创建工件. dev分支会自动部署,其他两个则不会.也有featurebugfixhotfix分支.这些分支应该建立,但不产生构件.如果他们的代码有问题,应仅将它们用于通知开发人员.

We are using a gitflow pattern with dev, release, and master branches that all are used to create artifacts. The dev branch auto deploys, the other two do not. Also there are feature, bugfix and hotfix branches. These branches should be built, but not produce an artifact. They should just be used to inform the developer if there is a problem with their code.

在标准构建中,我可以访问$GIT_BRANCH变量来了解正在构建哪个分支,但是该变量未在我的多分支管道中设置.我也尝试过env.GIT_BRANCH,并且尝试将$GIT_BRANCH作为参数传递给构建.似乎没有任何作用.我以为,由于构建知道正在构建的分支(我可以在控制台输出的顶部看到分支名称),因此我可以使用某些东西-我只是找不到对它的任何引用.

In a standard build, I have access to the $GIT_BRANCH variable to know which branch is being built, but that variable isn't set in my multibranch pipeline. I have tried env.GIT_BRANCH too, and I tried to pass $GIT_BRANCH as a parameter to the build. Nothing seems to work. I assumed that since the build knows about the branch being built (I can see the branch name at the top of the console output) that there is something that I can use - I just can't find any reference to it.

推荐答案

env.BRANCH_NAME变量包含分支名称.

The env.BRANCH_NAME variable contains the branch name.

Pipeline Groovy插件2.18 开始,您还可以只需使用BRANCH_NAME (env不是必需的,但仍被接受.)

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

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

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