jenkinsjenkins-pipelinejenkins-declarative-pipelinejenkins-blueocean

Sequential stages inside parallel in Scripted Pipeline syntax


In my Jenkinsfile I execute 2 stages in parallel and one of these stages would consist of few other sequential stages. When I run the script and check the pipeline in BlueOcean, that sequence of stages is represented as one single node.

The (simplified) script is as follows :

node {
    stage('Stage 1') {...}
    stage('Stage 2') {...}
    stage('Stages 3 & 4 in parallel') {
        parallel(
            'Stage 3': {
                stage('Stage 3') {...}
            },
            'Stage 4': {
                stage('Stage 4a') {...}
                stage('Stage 4b') {...}
            }
        )
    }
}

So in BlueOcean this script results in one node for stage 4 while I wish to see two nodes as it is composed of two sequential stages.


Solution

  • I too have faced the same issue with Scripted pipelines. If you are fine with Declarative pipelines, you can use this:

    pipeline {
        agent any
        stages {
            stage('Stage 1') { steps {pwd()}}
            stage('Stage 2') { steps {pwd()}}
            stage('Stages 3 & 4 in parallel') {
                parallel {
                    stage('Stage 3') { steps {pwd()}}
                    stage('Stage 4') {
                        stages {
                            stage('Stage 4a') { steps {pwd()}}
                            stage('Stage 4b') { steps {pwd()}}
                        }
                    }
                }
            }
        }
    }
    

    enter image description here