Scripted jenkinsfile parallel stage

后端 未结 6 1619
星月不相逢
星月不相逢 2020-12-07 19:26

I am attempting to write a scripted Jenkinsfile using the groovy DSL which will have parallel steps within a set of stages.

Here is my jenkinsfile:

n         


        
6条回答
  •  清歌不尽
    2020-12-07 19:47

    To simplify the answer of @Ed Randall here. Remember this is Jenkinsfile scripted (not declarative)

    stage("Some Stage") {
        // Stuff ...
    }
    
    
    stage("Parallel Work Stage") {
    
        // Prealocate dict/map of branchstages
        def branchedStages = [:]
    
        // Loop through all parallel branched stage names
        for (STAGE_NAME in ["Branch_1", "Branch_2", "Branch_3"]) {
    
            // Define and add to stages dict/map of parallel branch stages
            branchedStages["${STAGE_NAME}"] = {
                stage("Parallel Branch Stage: ${STAGE_NAME}") {
                    // Parallel stage work here
                    sh "sleep 10"
                }
            }
    
        }
    
        // Execute the stages in parallel
        parallel branchedStages
    }
    
    
    stage("Some Other Stage") {
        // Other stuff ...
    }
    

    Please pay attention to the curly braces. This will result in the following result (with the BlueOcean Jenkins Plugin):

    Scripted Jenkinsfile Result Link

提交回复
热议问题