How can I trigger a Jenkins job upon completion of a set of other jobs?

﹥>﹥吖頭↗ 提交于 2019-12-12 13:15:32

问题


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.

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.

update

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

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

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.

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.

update 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.

update 3

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...


回答1:


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'
}

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




回答2:


As far as I can tell, there is no published solution to my problem, so I have to roll my own. The following system groovy script works, but can obviously use some enhancements. Specifically, I really miss a nice simple one page build status overview...

This gist implements my solution, including proper handling of job cancellations: https://gist.github.com/cg-soft/0ac60a9720662a417cfa




回答3:


You can use Build other projects as Post Build Actions in the configuration of one of your parent job which would trigger second parent job on successful build of the job. When the second parent job also gets completed, trigger your child job by same method.




回答4:


Multijob plugin could be used to make hierarchy of jobs.

First select Multijob Project in new item and then in configuration you can add as many jobs as you want. You need to also specify phase for each Job.



来源:https://stackoverflow.com/questions/32704360/how-can-i-trigger-a-jenkins-job-upon-completion-of-a-set-of-other-jobs

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