詹金斯为什么允许指定多个git分支?
Multiple times now I have stumbled over why does Jenkins support multiple "branches to build", considering that the help text does not recommend it, what would be a valid use-case?
Edit: I am referring to why there is the "Add branch" button in a single Job, not Multi-Branch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法解释什么用例,但是通过读取源代码,Git插件中似乎有一个“高级用例”,该插件选择一个单个分支*(参考),并为其他构建安排新构建。
必须注意的是,安排新版本仅限于作业,其实现从
AbstractProject
(例如自由式作业)继承。请注意,管道作业不是AbstractProject
!*有“构建选择器”可用,可以订购或限制匹配的分支/参考。
选择代码摘录:
( source )
调度新构建:
( source )
I cannot explain what a use-case would be, but from reading the source code there seems to be an "advanced use-case" in the git plugin which selects a single branch* (ref) and schedules a new build for the other ones.
It must be noted that scheduling new builds is limited to jobs whose implementation inherits from
AbstractProject
, like Free-Style Jobs. Note well that Pipeline Jobs are notAbstractProjects
!* There are "build choosers" available which order or limit the matched branches/refs.
Selection code excerpt:
(source)
scheduling new build:
(source)
在最新版本的插件中,您有更具描述性的解释。
让我回答您的问题。这确实归结为一个问题,为什么要在git中创建多个分支?适用于CICD管道的典型示例是。假设您有一些将部署到不同环境的代码。因此,在代表不同环境的订单中,您可以创建分支。例如,
开发
, test ,生产
等。开发人员将在开发完成后在开发分支上工作,将在生产中传播。开发分支将合并以测试然后进行生产。这是詹金斯进入图片的地方。在对相关分支的每个提交中,您需要将此代码部署到相关环境并执行此操作,您可以创建单个管道来处理部署过程。例如,查看以下管道。
You have a more descriptive explanation in the latest version of the plugin.
Let me answer your question. This really boils down to the question why would you want to create multiple branches in Git? A typical example that is applicable to a CICD pipeline is. Let's say you have some code that will be deployed to different environments. So inorder to represent different environments you can create branches. For example
develop
,test
,production
etc. Developers will work on develop branch when the development is completed it will be propagated upto production. Develop branch will be merged to test and then to production. This is where Jenkins comes into the picture. On each commit to the relevant branch you need to deploy this code to a relevant environment and to do this you can create a single pipeline to handle the deployment process.For example look at the following pipeline.