在Jenkins管道中的并行阶段中设置依赖项或优先级 [英] Setting Dependencies or Priorities in parallel stages in Jenkins pipeline

查看:521
本文介绍了在Jenkins管道中的并行阶段中设置依赖项或优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做--

stages {
    stage ('Parallel build LEVEL 1 - A,B,C ...') {
        steps{
            parallel (
                "Build A": {
                    node('Build_Server_Stack') {
                        buildAndArchive(A) // my code
                    }
                },
                "Build B" : {
                    node('Build_Server_Stack') {
                        buildAndArchive(B)
                    }
                },
                "Build C" : {
                    node('Build_Server_Stack') {
                        buildAndArchive(C)
                    }
                }
            )
        }
    }
}

现在我需要在C完成之后开始执行B.我可以将B作业从并行块中拉出,并在并行块之后添加以实现此目的.但是在那种情况下,只有在A和C完成之前B才会启动.对于长期的A作业,当您有可用的空闲构建服务器时,这会影响性能. 我们能否解决/改进执行计划以使其全部并行运行,但并行步骤具有依赖项"或优先级". Promotions插件中也存在类似的机制,但需要在管道中实现.

Now I require to start the execution of B, after C is done. I can pull the B job out of the parallel block and add after the parallel block to achieve this. But in that case B will not be started until A and C completes. For a long A job, this impacts performance, when you have idle build servers available. Can we solve/improve the execution plan to run all in parallel, but with 'Dependencies' or 'Priorities' for parallel steps. Similar mechanism exists in Promotions plugin, but need to implement in pipeline.

推荐答案

您绝对可以.尝试这样的事情:

You most definitely can. Try something like this:

stages {
    stage ('Parallel build LEVEL 1 - A/C+B ...') {
        parallel {
            stage("Build A") {
                agent { node { label 'A'}}
                steps {
                    buildAndArchive(A)
                }
            }
            stage("Build C and B") {
              stages {
                stage("Build C") {
                  agent { node { label 'C'}}
                  steps {
                      buildAndArchive(C)
                  }
                }
                stage("Build B") {
                  agent { node { label 'B'}}
                  steps {
                      buildAndArchive(B)
                  }
                }
              }

这将并行执行两个分支,其中一个分支在构建A,另一个在先构建C,然后在B.

This will execute two branches in parallel, where one is building A, and the other sequentially building C and then B.

另请参见 https: //jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/

这篇关于在Jenkins管道中的并行阶段中设置依赖项或优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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