我想在詹金斯建立一条流水线,其中基于多个上游作业的结果应触发一个下游作业.
I would like to build a Pipeline in Jenkins where result based on multiple upstream jobs should trigger a single downstream job.
例如:
Job 1 --> Job 2 --> Job 5 --> Job 6 Job 3 --> Job 4 -->作业1:将新代码提交给Git生产时,它应该触发Jobs 2,3和4(这部分我可以使用Post Build Action中的Build Other Jobs选项运行;尽管有任何建议可以改进)也非常感谢).
Job 1: when a new piece of code is committed to Git production it should trigger Jobs 2,3 and 4 (this part I was able to run run using Build Other jobs option in Post Build Action; although any suggestion to improve this is also greatly appreciated).
作业2,3和4是要在不同的测试机上运行的回归.
Job 2,3 and 4 are regressions to be run on different test machines.
我无法确定的部分仅是当Job 2,3和4成功时,它应该触发下游Job 5,最终5可以触发6.
The part I am not able to fig out is only when Job 2,3 and 4 are successful it should trigger the downstream Job 5 and eventually 5 can trigger 6.
我目前正在使用Build Pipeline插件,但是对于一个(下游)到许多(上游)工作却是成功的,反之亦然.
I am currently using the Build Pipeline plugin, but it was successful for one (downstream) to many (upstream )jobs and not vice versa.
非常感谢您的帮助/建议/指导.提前致谢! 干杯!
Any help/suggestion/guidance is greatly appreciated. Thanks in advance! Cheers!!
推荐答案您可以通过在Job 5配置的构建触发器"部分中使用在构建其他项目之后构建"来执行此操作.在那里,您将Job2,Job3和Job4添加为依赖项,并设置了仅在构建稳定时才触发"选项(如下图所示).这样就可以完成工作,并等待三个工作完成.
you can do this by using the 'Build after other projects are built' on Job 5 configuration 'Build Triggers' section. There you add Job2, Job3 and Job4 as dependencies and set up the option 'Trigger only if build is stable' (As the image below). This should do the job, and will wait the three jobs to finish.
但是,正如您所说,当Job2,3和4成功时(即使其中一个失败,Job5也会执行),这并没有达到执行Job5的目标.我认为,针对您的情况的最佳解决方案是使用一个新作业并将其创建为管道"作业(我们称其为PipelineJob).这样,您不必使用自己的配置和依赖项来编辑每个作业,并且可以更轻松地调整管道行为.同样由于错误传播,如果某个阶段也失败,它将失败!这应该可以按预期工作:
But this as you said does not accomplish the goal of executing Job5 when Job2,3 and 4 are successful (Job5 gets executed even though one of them failed). I think the best solution for your case is to use a new job and create it as a 'Pipeline' job (let's call it PipelineJob). This way you do not have to edit every single Job with its own configuration and dependencies and you can tweak your pipeline behaviour easier. Also thanks to error propagation it will fail if some phase fails too! This should work as intended:
pipeline { agent any stages{ stage('Phase 1') { steps { build 'Job1' } } stage('Phase 2') { parallel { stage('Job 2') { steps { build 'Job2' } } stage('Job 3') { steps { build 'Job3' } } stage('Job 4') { steps { build 'Job4' } } } } stage('Phase 3') { steps { build 'Job5' } } stage('Phase 4') { steps { build 'Job6' } } } }更多推荐
Jenkins:基于多个上游作业触发单个下游作业
发布评论