4

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.

nandilov
  • 699
  • 8
  • 18
C. Güzelhan
  • 153
  • 3
  • 12
  • Scripted pipeline seems to be treated poorly in Blue Ocean UI, as you have noticed. I don't see a reason to still use scripted syntax as you can have `script` blocks in declarative syntax if you need to code more freely. – zett42 Feb 14 '20 at 18:06

2 Answers2

9

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

Dibakar Aditya
  • 3,893
  • 1
  • 14
  • 25
  • Thank you for the solution. It required some refactoring to do to switch from scripted to declarative but it does look better. :) – C. Güzelhan Feb 24 '20 at 10:35
1

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")}
          }
      )
   }
}