C. Güzelhan
C. Güzelhan

Reputation: 171

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.

Upvotes: 5

Views: 6553

Answers (2)

Damien Merlin
Damien Merlin

Reputation: 11

With latest version of jenkins 2.235.3 and latest plugins this is working now in scripted pipeline.

pipeline scripted image

node ('fetch') {
   stage('Stage 1') { sh(script:"echo Stage1",label: "sh echo stage 1")}
   stage('Stage 2') { sh(script:"echo Stage2",label: "sh echo stage 2")}
   stage('Stages 3 & 4 in parallel') {
       parallel(
           'Stage 3': {
            stage('Stage 3') {sh(script:"echo Stage3",label: "sh echo stage 3")}
           },
          'Stage 4': {
              stage('Stage 4a') {sh(script:"echo Stage4a",label: "sh echo stage 4a")}
              stage('Stage 4b') {sh(script:"echo Stage4b",label: "sh echo stage 4b")}
          }
      )
   }
}

Upvotes: 1

Dibakar Aditya
Dibakar Aditya

Reputation: 4203

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

Upvotes: 9

Related Questions