Sequential stages inside parallel in Scripted Pipeline syntax
Asked Answered
E

2

5

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.

European answered 14/2, 2020 at 16:54 Comment(1)
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.Kessel
M
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

Morion answered 14/2, 2020 at 17:32 Comment(1)
Thank you for the solution. It required some refactoring to do to switch from scripted to declarative but it does look better. :)Balough
M
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")}
          }
      )
   }
}
Mudlark answered 4/8, 2020 at 14:20 Comment(2)
This one works, but is basically a declarative pipeline disguised as scriptEvesham
I agree that with the latest version it woked issues.jenkins.io/browse/JENKINS-53751Mannered

© 2022 - 2024 — McMap. All rights reserved.