Jenkins Multibranch管道:分支名称变量是什么? [英] Jenkins Multibranch pipeline: What is the branch name variable?

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

问题描述

我是Jenkins Pipeline插件的新手,尤其是多分支管道插件的新手.在标准构建中,我可以访问$ GIT_BRANCH变量,以了解正在构建哪个分支.但是,该变量未在多分支管道中设置.我也尝试过env.GIT_BRANCH,并且尝试将$ GIT_BRANCH作为参数传递给构建.似乎没有任何作用.我以为既然该构建知道所构建的分支(我可以在控制台输出的顶部看到该分支的名称,可以使用某些东西,但找不到任何引用.

I'm new to the Jenkins Pipeline plugin, and especially new to the multibranch pipeline plugin. In a standard build I have access to the $GIT_BRANCH variable to know which branch is being built. However that variable isn't set in the 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.

这是为什么这很重要的一个例子.我们正在使用gitflow模式.我们拥有dev,release和master分支,所有这些分支都用于创建构件. dev分支会自动部署,其他两个则不会.也有功能,错误修正和修补程序分支.这些分支应该建立,但不产生构件.如果它们的代码有问题,则仅应使用它们来通知开发人员.我需要知道要建立哪个分支才能运行正确的步骤.

Here is an example of why this is important. We are using a gitflow pattern. We have 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. I need to know which branch is being built in order to run the correct steps.

任何帮助将不胜感激.

Any help would be appreciated.

推荐答案

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 Multibranch管道:分支名称变量是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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