简体   繁体   English

如何在 Jenkins 声明式管道中并行运行有和没有矩阵的阶段?

[英]How to run stages with and without matrix in parallel in Jenkins declarative-pipeline?

I am trying to run non-matrix stage with matrix stage in parallel.我正在尝试并行运行非矩阵阶段和矩阵阶段。 I want stage ('Build - Win Mac') & stage ('Build - Linux') to run parallel.我希望阶段('Build - Win Mac')和阶段('Build - Linux')并行运行。 As per https://www.jenkins.io/doc/book/pipeline/syntax/#declarative-matrix "It is not possible to nest a parallel or matrix block within a stage directive if that stage directive is nested within a parallel or matrix block itself".根据https://www.jenkins.io/doc/book/pipeline/syntax/#declarative-matrix “如果阶段指令嵌套在并行或矩阵指令中,则不可能在阶段指令中嵌套并行或矩阵块矩阵块本身”。 So I am looking for a workaround for this situation.所以我正在寻找解决这种情况的方法。 Please find below my sample stages and suggest how i can achieve this请在下面找到我的示例阶段并建议我如何实现这一目标

stages {
    stage ('Build') {
        stage ('Build - Win Mac') {
          // non-docker build for Win & Mac using Matrix
          matrix {
                axes {
                    axis {
                        name 'PLATFORM'
                        values 'Win', 'Mac'
                    }
                    axis {
                        name 'ADDRESS_SANITIZER'
                        values 'disabled', 'enabled'
                    }
                }
            stage ('build'){
                steps {
                    // build step for win, mac
                }
            }
       }
       stage ('Build - Linux'){
       // docker build for Linux
       }
    }
}

I can't make it with a pure declarative pipeline but If you mix declarative + scripted it can be possible我不能用纯声明式管道来实现,但如果你混合声明式+脚本化,它是可能的

pipeline {
    agent any;
    stages {
        stage('parallel') {
            parallel {
                stage('metrix-build') {
                    steps {
                        echo "Metric-Build"
                        // will take care Metrix kind of scenario with scripted way [start]
                        script {
                            def axisNode = ["osx-agent-1","osx-agent-2"]
                            def axisTool = ["jdk7","jdk8"]
                            def tasks = [:]
                            
                            for(int i=0; i< axisNode.size(); i++) {
                                def axisNodeValue = axisNode[i]
                                for(int j=0; j< axisTool.size(); j++) {
                                    def axisToolValue = axisTool[j]
                                    tasks["${axisNodeValue}/${axisToolValue}"] = {
                                        node(axisNodeValue) {
                                            def javaHome = tool axisToolValue
                                            println "Node=${env.NODE_NAME}"
                                            println "Java=${javaHome}"
                                        }
                                    }
                                }
                            }
                            parallel tasks
                        } 
                        //[End here]
                        
                    }
                }
                stage('non-metric-build') {
                    steps {
                        echo "non metrics build"
                    }
                }
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Jenkins declarative-pipeline 中与矩阵并行运行非矩阵阶段 - Running non-matrix stages in parallel to a matrix in Jenkins declarative-pipeline 如何在隔离的 Pod 中为声明性 jenkins 管道运行并行阶段 - How to run parallel stages in isolated pods for a declarative jenkins pipeline Jenkins Declarative Pipeline并行阶段 - Jenkins Declarative Pipeline parallel stages 詹金斯:如何在詹金斯声明式管道中实现并行动态阶段 - Jenkins:How to Achieve parallel dynamic stages in jenkins declarative pipeline 如何在 Jenkins 声明式管道中循环参数化并行阶段? - How to loop parametrized parallel stages in Jenkins declarative pipeline? 如何使用声明性Jenkins管道在同一节点上运行多个阶段? - How to run multiple stages on the same node with declarative Jenkins pipeline? 是否可以在循环中创建并行的Jenkins声明管道阶段? - Is it possible to create parallel Jenkins Declarative Pipeline stages in a loop? 如何锁定声明性 Jenkins 管道的多个阶段? - How to lock multiple stages of declarative Jenkins pipeline? 具有强制阶段的 Jenkins 声明式管道 - Jenkins Declarative Pipeline with Mandatory stages 在循环 Jenkins 声明式管道中创建嵌套的并行阶段 - create nested parallel stages in a loop Jenkins declarative pipeline
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM