Jenkins Multibranch Config:如何根据可变字符串过滤分支? [英] Jenkins Multibranch Config: How to Filter branches based on variable string?

查看:425
本文介绍了Jenkins Multibranch Config:如何根据可变字符串过滤分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们让Jenkins建立了7个多分支管道项目,每个项目都基于相同的git repo构建,但是针对不同的目标平台.这些多分支管道中的每一个都建立了许多分支.当前,我们通过在多分支项目配置中使用以下属性来设置每个多分支管道构建的分支:

We have Jenkins set up with 7 multibranch pipeline projects, each building off the same git repo, but for different target platforms. Each of these multibranch pipelines builds a number of branches. We currently set which branches each multibranch pipeline builds by using the following property in the multibranch project configuration:

Branch Sources -> Git -> Behaviors -> Filter by name (with wildcards)

当前,每个多分支管道在此Filter by name (with wildcards)字段中具有相同的分支字符串.每次我们希望Jenkins开始建立一个新分支时,我们都要遍历所有7个多分支项目配置,并更新此字段以包括新分支.

Currently, each multibranch pipeline has the same string of branches in this Filter by name (with wildcards) field. Each time we want Jenkins to start building a new branch, we go through all 7 multibranch project configurations and update this field to include the new branch.

遍历每个配置并每次更改此字段都有些麻烦,因为我们一直希望每个配置都具有相同的分支列表.是否可以在此字段中简单地使用某种类型的变量?这样,我们只需要更改一个位置即可,而不必尝试使7个不同的配置彼此保持同步,这容易出错,也很痛苦.

It's a bit of a pain to go through each configuration and change this field every time, since we always want each configuration to have the same list of branches. Is it possible to simply use some type of a variable in this field? This way we only would need to change one location instead of trying to keep 7 different configurations in sync with each other, which is prone to error and also a bit of a pain.

感谢您的帮助! 艾伦

推荐答案

您可以尝试使用正则表达式过滤分支,而不是使用通配符过滤.在我们的情况下,模式如下:

Rather than filtering with wildcards, you could try filtering branches with regular expression. In our case, pattern like:

(master|develop|release.*|feature.*|bugfix.*)

在覆盖资料库方面一直表现良好.也就是说,假设您遵循 Git Flow 或类似方法.不幸的是,没有一种简单的方法可以在一个存储库中的MultiBranch Pipelines构建之间同步配置. Multibranch Pipeline和Organization插件均未设计为可与多个Jenkinsfiles一起使用.

has been working well to cover the repository. That is, assuming that you follow Git Flow or similar methodology. Unfortunately, there is no simple way to sync the configuration between MultiBranch Pipelines build from one repository. Neither Multibranch Pipeline, nor Organization plugins are designed to work with Multiple Jenkinsfiles.

此外,您可以尝试使用Jenkins脚本控制台仅同步项目之间的分支配置.不必在项目级别上设置大多数作业配置.例如,您可以创建将由其他作业来源的共享脚本(或共享库),以在每个作业上设置相同的作业属性.请参阅如何加载并执行Groovy文件了解详情.

Also, you can try to sync only the branch configuration between Projects using Jenkins script console. Most of the Job configuration does not have to be set on Project level. For instance, you can create shared script (or shared library) to would be sourced by other jobs, to set the same job properties on each of them. See How do you load a groovy file and execute it for details.

这篇关于Jenkins Multibranch Config:如何根据可变字符串过滤分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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