Jenkins 多分支管道的分支名称变量是什么? [英] What is the branch name variable for Jenkins multibranch pipelines?
问题描述
我需要知道我的 Jenkins 多分支管道中正在构建哪个分支,以便它正确运行步骤.
I need to know which branch is being built in my Jenkins multibranch pipeline in order for it to run steps correctly.
我们正在使用带有 dev
、release
和 master
分支的 gitflow 模式,这些分支都用于创建工件.dev
分支自动部署,其他两个没有.还有 feature
、bugfix
和 hotfix
分支.应该构建这些分支,但不会产生工件.如果他们的代码有问题,它们应该只用于通知开发人员.
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
变量包含分支名称.
从 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屋!