完成其他一系列工作后,如何触发詹金斯工作? [英] How can I trigger a Jenkins job upon completion of a set of other jobs?

查看:157
本文介绍了完成其他一系列工作后,如何触发詹金斯工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一种简单的情况是,您只有一个工作取决于一组其他工作的完成,这很容易:要么使用多任务,要么使用带有parallel { ... }的构建流程插件.我要解决的情况比较笼统,例如:

The simple case where you just have one job depending on the completion of a set of other jobs is easy: either use a multijob or use the build flow plugin with parallel { ... }. The case I am trying to solve is more general, for example:

JobA depends on JobX and JobZ
JobB depends on JobY and JobZ
SuperJob depends on JobA and JobB

我希望每个作业都在其先决条件完成时立即触发.

I want each of these jobs to trigger as soon as, and only when their prerequisites complete.

看来,构建流程插件,join插件或job DSL插件都没有很好的机制.当然,我可以开始我的所有工作,然后让他们对詹金斯进行投票,但这将非常丑陋.

It would appear that neither the build flow plugin, nor the join plugin or the job DSL plugin have a good mechanism for this. I can, of course, just start all my jobs and have them poll Jenkins, but that would be quite ugly.

另一个死角是上游作业触发器".我想触发一个特定的工作版本,而不仅仅是上游工作的任何运行.

Another dead end is the "Upstream job trigger". I want to trigger off a specific build of a job, not just any run of an upstream job.

更新

一个答案提到了multijob插件.它确实可以用来解决此问题,但是调度和总构建时间几乎总是最坏的情况.例如,假设此依赖关系图的构建时间如下所示:

One answer mentions the multijob plugin. It can indeed be used to solve this problem, but the scheduling and total build time is almost always worst case. For example, assume this dependency graph, with the build times as indicated:

left1 (1m)  right1 (55m)
   |            |
left2 (50m) right2 (2m)
   |____________|
         |
        zip

使用multijob插件,您将得到:

With the multijob plugin, you get:

Phase 1:
   left1, right1  // done in 55m
Phase 2:
   left2, right2  // done in 50m
Phase 3:
    zip   // total time 105m

如果在完成所有先决条件后我有一种方法可以准确触发下一个作业,那么总构建时间将仅为57m.

If I had a way to trigger the next job exactly when all prerequisites are done, then the total build time would be just 57m.

这里的答案应该说明我如何才能获得这种行为,最好不要编写自己的轮询机制.

The answer here should explain how I can obtain that behavior, preferably without writing my own polling mechanism.

更新1 1/2 在下面的注释中,建议将左任务和右任务分组为一个子任务.是的,可以在此示例中完成此操作,但是通常很难自动完成此操作.例如,假设存在其他依赖项:right2依赖于left1.在给定的构建时间的情况下,最佳构建时间不应更改,因为left1在启动right2之前已经完成了很长时间,但是如果不了解这一点,您将无法再将left1和left2集中在同一组中,而不会冒没有right1的风险.可用.

update 1 1/2 In the comments below, it was suggested I group the left tasks and the right tasks into a single subtask. Yes, this can be done in this example, but it is very hard to do this in general, and automatically. For example, assume there is an additional dependency: right2 depends on left1. With the build times given, the optimal build time should not change, since left1 is long done before right2 is launched, but without this knowledge, you can no longer lump left1 and left2 in the same group, without running the risk of not having right1 available.

更新2

这里似乎没有现成的答案.看来我将不得不自己编写一个系统常规脚本.看到我对这个问题的回答.

It looks like there is no ready made answer here. It seems I am going to have to code up a system groovy script myself. See my own answer to the question.

更新3

我们最终分叉了multijob插件,并在其中编写了新逻辑.我希望我们可以在清理后将其作为新插件发布...

We ended up forking the multijob plugin and writing new logic within. I hope we can publish it as a new plugin after some cleanup...

推荐答案

自从您添加了jenkins-workflow标记以来,我想使用Jenkins Workflow插件就可以了,所以也许此Workflow脚本可以满足您的需求:

Since you added the jenkins-workflow tag, I guess that using Jenkins Workflow Plugin is ok to you, so perhaps this Workflow script fit your needs:

node {
    parallel left: {
        build 'left1'
        build 'left2'
    }, right: {
        build 'right1'
        build 'right2'
    },
    failFast: true

    build 'zip'
}

两个并行分支完成后,此工作流程将触发zip.

This workflow will trigger zip as soon as both parallel branches finish.

这篇关于完成其他一系列工作后,如何触发詹金斯工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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