Jenkins 多分支管道和指定上游项目 [英] Jenkins multi-branch pipeline and specifying upstream projects
问题描述
我们目前使用 Jenkins 作业 DSL 在每个 Git 分支的基础上生成大量 Jenkins 作业;多分支管道插件看起来是一种有趣的方式,可以使用 Jenkinsfiles 获得一流的作业生成支持,并减少我们维护的作业 DSL 的数量.
We currently generate a lot of Jenkins jobs on a per Git branch basis using Jenkins job DSL; the multi-branch pipeline plugin looks like an interesting way to potentially get first-class job generation support using Jenkinsfiles and reduce the amount of Job DSL we maintain.
例如我们有 libwidget-server 和 widget-server 开发分支项目.当 libwidget-server 构建完成时,将触发 widget-server 作业(对于开发分支).这也适用于其他分支.
For example we have libwidget-server and widget-server develop branch projects. When the libwidget-server build finishes then the widget-server job is triggered (for the develop branch). This applies to other branches too.
这利用 Build after other projects are built
在上游构建完成时触发(例如,libwidget-server 导致 widget-server 被构建).
This makes use of the Build after other projects are built
to trigger upon completion of an upstream build (e.g. libwidget-server causes widget-server to be built).
多分支管道插件似乎缺少构建其他项目后构建
设置 - 我们如何在多分支管道构建中完成上述操作?
It seems that the multi-branch pipeline plugin lacks the Build after other projects are built
setting - how would we accomplish the above in the multi-branch pipeline build?
推荐答案
您应该将分支名称添加到上游作业(假设您也为上游作业使用多分支管道).
You should add the branch name to your upstream job (assuming you are using a multi-branch pipeline for the upstream job too).
假设您有一个包含两个作业的文件夹,都是多分支管道作业:jobA
和 jobB
;jobB
应该在 jobA
的 master
之后触发.
Suppose you have a folder with two jobs, both multi-branch pipeline jobs: jobA
and jobB
; jobB
should trigger after jobA
's master
.
您可以将此代码段添加到 jobB
的 Jenkinsfile 中:
You can add this code snippet to jobB
's Jenkinsfile:
properties([
pipelineTriggers([
upstream(
threshold: 'SUCCESS',
upstreamProjects: '../jobA/master'
)
])
])
(注意这里jobB
的任何分支都会在jobA
的master之后触发!)
(Mind that any branch of jobB
here will trigger after jobA
's master!)
这篇关于Jenkins 多分支管道和指定上游项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!