Jenkins Multibranch Config: How to Filter branches based on variable string?

点点圈 提交于 2020-01-13 11:26:29

问题


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)

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.

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.

Thanks for your help! Allen


回答1:


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

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

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.

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.




回答2:


if you want to use the wildcard you can provide like below:

In this example it will discover only qa and dev branch.

NOTE: You have to use "Discover branches" also with "filter by name (with wildcards)" behaviour.


来源:https://stackoverflow.com/questions/50011523/jenkins-multibranch-config-how-to-filter-branches-based-on-variable-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!