Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-55438

Allow sequential stages inside parallel in Scripted syntax

      Similar to JENKINS-46809, I would like the Blue Ocean GUI to properly visualize multiple stages in sequence that are all parallel of each other. Below is an example image of what this looks like using declarative syntax (working):

       

      Here is the declarative example code I wrote to generate the example image:

      pipeline {
        agent { label 'master' }
        stages {
          stage('Build and Test') {
            parallel {
              stage("Build and Test Linux") {
                stages {
                  stage("Build (Linux)") {
                    agent any
                    steps {
                      echo "Inside for loop 1"
                    }
                  }
                  stage("Test (Linux)") {
                    agent any
                    steps {
                      echo "Inside for loop 2"
                    }
                  }
                }
              }
              stage("Build and Test Windows") {
                stages {
                  stage("Build (Windows)") {
                    agent any
                    steps {
                      echo "Inside for loop 3"
                    }
                  }
                  stage("Test (Windows)") {
                    agent any
                    steps {
                      echo "Inside for loop 4"
                    }
                  }
                }
              }
            }
          }
        }
      }

       

      Here is example scripted Jenkins code that I would like to use. Linux and windows build/test flows happen in parallel. Inside each flow in a "build" stage and then a "test" stage. The Windows sequential build/test flow should be displayed in parallel with the Linux build/test flow, but right now the separate Build/Test sequential stages are combined into one circle/stage when using the scripted syntax.

       

      pipeline {
        agent any
        stages {
          stage("Build and Test") {
            steps {
              script {
                parallel linux: {
                  node("linux_build") {
                    echo "Inside for loop 1"
                  }
                  node("linux_test") {
                    echo "Inside for loop 2"
                  }
                },
                windows: {
                  node("windows_build") {
                    echo "Inside for loop 3"
                  }
                  node("windows_test") {
                    echo "Inside for loop 4"
                  }
                }
              }
            }
          }
        }
      }
      

       

      This is what the scripted example code currently generates:

       

          [JENKINS-55438] Allow sequential stages inside parallel in Scripted syntax

          Jesse Glick added a comment -

          First of all, the second example is not Scripted syntax; it is pseudo-Declarative (pipeline) with a script block.

          Second, node is not a stage. Try using the actual stage step.

          If Blue Ocean in fact refuses to display a valid Scripted build with an identical structure of parallel / stage steps that is displayed when run from a Declarative build, then I would consider that a bug rather an RFE.

          Jesse Glick added a comment - First of all, the second example is not Scripted syntax; it is pseudo-Declarative ( pipeline ) with a script block. Second, node is not a stage . Try using the actual stage step. If Blue Ocean in fact refuses to display a valid Scripted build with an identical structure of parallel / stage steps that is displayed when run from a Declarative build, then I would consider that a bug rather an RFE.

          An Tran added a comment - - edited

          I can confirm that I have the same behaviour like that of the author. Only one stage of scripted pipeline in  parallel branches is shown

          pipeline {
            stages {
              stage('testing') {
                steps {
                  script {
                    parallel "task1": {
                        node("ios") {
                          stage("build") {
                              echo "windows-build"
                          }
                          stage("deploy") {
                              echo "windows-deploy"
                          }
                        }
                    },
                    "task2": {
                      node("ios") {
                        stage("build") {
                            echo "windows-build"
                        }
                        stage("deploy") {
                            echo "windows-deploy"
                        }
                      }
                    }
                  }
                }
              }
            }
          }

           

          An Tran added a comment - - edited I can confirm that I have the same behaviour like that of the author. Only one stage of scripted pipeline in  parallel branches is shown pipeline { stages { stage( 'testing' ) { steps { script { parallel "task1" : { node( "ios" ) { stage( "build" ) { echo "windows-build" } stage( "deploy" ) { echo "windows-deploy" } } }, "task2" : { node( "ios" ) { stage( "build" ) { echo "windows-build" } stage( "deploy" ) { echo "windows-deploy" } } } } } } } }  

          Jesse Glick added a comment -

          peacemoon again that is not Scripted syntax. It is a script block inside Declarative syntax.

          Jesse Glick added a comment - peacemoon again that is not Scripted syntax. It is a script block inside Declarative syntax.

          An Tran added a comment -

          jglick Ok, so what is the correct way to do it?

          An Tran added a comment - jglick Ok, so what is the correct way to do it?

          Jesse Glick added a comment -

          I do not know, you would need to experiment.

          Jesse Glick added a comment - I do not know, you would need to experiment.

          An Tran added a comment -

          I did experiment a lot already before asking here

          Ok let's keep the terminology aside.

          Can you help me to understand why only one stage is shown in each parallel branch even though I habe 2 stages for each branch in my script? Is it a bug? Should I create a bug report for that?

          An Tran added a comment - I did experiment a lot already before asking here Ok let's keep the terminology aside. Can you help me to understand why only one stage is shown in each parallel branch even though I habe 2 stages for each branch in my script? Is it a bug? Should I create a bug report for that?

          Jesse Glick added a comment -

          I do not know how Blue Ocean works in any detail. My comment was very much about the terminology. None of the examples given so far in this issue are using actual Scripted syntax—they all start with pipeline, which is Declarative syntax, and so all bets are off.

          At any rate, the closest Scripted analogue I can come up with for the original Declarative script would be

          parallel 'Build and Test Linux': {
              stage("Build (Linux)") {
                  echo "Inside for loop 1"
              }
              stage("Test (Linux)") {
                  echo "Inside for loop 2"
              }
          }, 'Build and Test Windows': {
              stage("Build (Windows)") {
                  echo "Inside for loop 3"
              }
              stage("Test (Windows)") {
                  echo "Inside for loop 4"
              }
          }
          

          which indeed also fails to display the stages—only the branches are shown. (Similarly when the whole script is enclosed in stage('Build and Test') {…}.)So I would consider that a bug in Blue Ocean: it should display a Pipeline build with a structure that its visualization layer supports, regardless of the syntax used to run that build. Perhaps there is some workaround that a B.O. developer could explain.

          Jesse Glick added a comment - I do not know how Blue Ocean works in any detail. My comment was very much about the terminology. None of the examples given so far in this issue are using actual Scripted syntax—they all start with pipeline , which is Declarative syntax, and so all bets are off. At any rate, the closest Scripted analogue I can come up with for the original Declarative script would be parallel 'Build and Test Linux' : { stage( "Build (Linux)" ) { echo "Inside for loop 1" } stage( "Test (Linux)" ) { echo "Inside for loop 2" } }, 'Build and Test Windows' : { stage( "Build (Windows)" ) { echo "Inside for loop 3" } stage( "Test (Windows)" ) { echo "Inside for loop 4" } } which indeed also fails to display the stages—only the branches are shown. (Similarly when the whole script is enclosed in stage('Build and Test') {… }.)So I would consider that a bug in Blue Ocean: it should display a Pipeline build with a structure that its visualization layer supports, regardless of the syntax used to run that build. Perhaps there is some workaround that a B.O. developer could explain.

          An Tran added a comment -

          jglick From what I see in last comment int this ticket here https://issues.jenkins-ci.org/browse/JENKINS-53048?focusedCommentId=351304&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-351304 , acarr468 really wants to have an improvement instead of a bug report because the UI really on supports only declarative syntax of parallel command. If there is a bug, I would open a new one and keep this as improvement.

          An Tran added a comment - jglick From what I see in last comment int this ticket here https://issues.jenkins-ci.org/browse/JENKINS-53048?focusedCommentId=351304&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-351304  , acarr468 really wants to have an improvement instead of a bug report because the UI really on supports only declarative syntax of parallel command. If there is a bug, I would open a new one and keep this as improvement.

          Jesse Glick added a comment -

          Contra olamy’s comment there I consider this a bug. Blue Ocean should pay attention to the build metadata as provided by official Pipeline APIs and may not make assumptions about the mechanism used to run a build, except insofar as that is intrinsically required for a certain feature. (For example, a stage restart button should only appear next to a Declarative stage, because the feature of restarting a stage is tied to Declarative semantics.)

          Regardless of how the issue is classified, the question of whether it will be fixed or not depends entirely on the development team’s time and priorities.

          Jesse Glick added a comment - Contra olamy ’s comment there I consider this a bug. Blue Ocean should pay attention to the build metadata as provided by official Pipeline APIs and may not make assumptions about the mechanism used to run a build, except insofar as that is intrinsically required for a certain feature. (For example, a stage restart button should only appear next to a Declarative stage, because the feature of restarting a stage is tied to Declarative semantics.) Regardless of how the issue is classified, the question of whether it will be fixed or not depends entirely on the development team’s time and priorities.

          An Tran added a comment -

          An Tran added a comment - I found some tickets that maybe related: https://issues.jenkins-ci.org/browse/JENKINS-53751 https://issues.jenkins-ci.org/browse/JENKINS-53162  

          Adam Carroll added a comment -

          Thanks jglick and peacemoon for digging into this more! I personally am not concerned whether or not this is a bug or improvement, as long as it is fixed . It does sound a lot like a bug to me, but I do understand the argument for it being an improvement. Whatever the best path to resolution is will be fine with me.

          Based on the tickets peacemoon linked above, it looks like others desire this functionality as well.

          Adam Carroll added a comment - Thanks jglick and peacemoon for digging into this more! I personally am not concerned whether or not this is a bug or improvement, as long as it is fixed . It does sound a lot like a bug to me, but I do understand the argument for it being an improvement. Whatever the best path to resolution is will be fine with me. Based on the tickets peacemoon linked above, it looks like others desire this functionality as well.

          Mahima Mishra added a comment - - edited

          I am also stuck in the same situation, where I need to use scripted parallel block within declarative and the blueocean view is doesn't display the stages for scripted block correctly.

          Mahima Mishra added a comment - - edited I am also stuck in the same situation, where I need to use scripted parallel block within declarative and the blueocean view is doesn't display the stages for scripted block correctly.

          Here I share three code examples (bottom of this comment)

          1. declarative parallel within declarative pipeline
          2. scripted parallel within scripted pipeline
          3. scripted parallel within declarative pipeline

          The first two get visualized as expected.

          The third one gets a messed up visualization starting at the parallel part, i.e. also affects the next non-parallel stage.

          The code

          • declarative parallel within declarative pipeline
            pipeline {
                agent("none")
                stages {
                    stage("prepare") {steps {echo "prepare"}}
                    stage("build") {steps {echo "build"}}
                    stage("test") {
                        parallel {
                            stage("linux") {
                                stages {
                                    stage("install") {steps {echo "installing in linux"}}
                                    stage("test") {steps {echo "testing in linux"}}
                                }
                            }
                            stage("windows") {
                                stages {
                                    stage("install") {steps {echo "installing in windows"}}
                                    stage("test") {steps {echo "testing in windows"}}
                                }
                            }
                            stage("mac") {
                                stages {
                                    stage("install") {steps {echo "installing in mac"}}
                                    stage("test") {steps {echo "testing in mac"}}
                                }
                            }
                        }
                    }
                    stage("cleanup") {steps {echo "cleanup"}}
                }
            }
            
          • scripted parallel within scripted pipeline
            stage("prepare") {echo "prepare"}
            stage("build") {echo "build"}
            stage("test") {
                parallel ([
                    "linux": {
                        stage("install") {echo "installing in linux"}
                        stage("test") {echo "testing in linux"}
                    },
                    "windows": {
                        stage("install") {echo "installing in windows"}
                        stage("test") {echo "testing in windows"}
                    },
                    "mac": {
                        stage("install") {echo "installing in mac"}
                        stage("test") {echo "testing in mac"}
                    }
                ])
            }
            stage("cleanup") {echo "cleanup"}
            
          • scripted parallel within declarative pipeline
            pipeline {
                agent("none")
                stages {
                    stage("prepare") {steps {echo "prepare"}}
                    stage("build") {steps {echo "build"}}
                    stage("test") {
                        steps {
                            script {
                                parallel ([
                                    "linux": {
                                        stage("install") {echo "installing in linux"}
                                        stage("test") {echo "testing in linux"}
                                    },
                                    "windows": {
                                        stage("install") {echo "installing in windows"}
                                        stage("test") {echo "testing in windows"}
                                    },
                                    "mac": {
                                        stage("install") {echo "installing in mac"}
                                        stage("test") {echo "testing in mac"}
                                    }
                                ])
                            }
                        }
                    }
                    stage("cleanup") {steps {echo "cleanup"}}
                }
            }

             

          Alberto Arango added a comment - Here I share three code examples (bottom of this comment) declarative parallel within declarative pipeline scripted parallel within scripted pipeline scripted parallel within declarative pipeline The first two get visualized as expected. The third one gets a messed up visualization starting at the parallel part, i.e. also affects the next non-parallel stage. The code declarative parallel within declarative pipeline pipeline { agent( "none" ) stages { stage( "prepare" ) {steps {echo "prepare" }} stage( "build" ) {steps {echo "build" }} stage( "test" ) { parallel { stage( "linux" ) { stages { stage( "install" ) {steps {echo "installing in linux" }} stage( "test" ) {steps {echo "testing in linux" }} } } stage( "windows" ) { stages { stage( "install" ) {steps {echo "installing in windows" }} stage( "test" ) {steps {echo "testing in windows" }} } } stage( "mac" ) { stages { stage( "install" ) {steps {echo "installing in mac" }} stage( "test" ) {steps {echo "testing in mac" }} } } } } stage( "cleanup" ) {steps {echo "cleanup" }} } } scripted parallel within scripted pipeline stage( "prepare" ) {echo "prepare" } stage( "build" ) {echo "build" } stage( "test" ) { parallel ([ "linux" : { stage( "install" ) {echo "installing in linux" } stage( "test" ) {echo "testing in linux" } }, "windows" : { stage( "install" ) {echo "installing in windows" } stage( "test" ) {echo "testing in windows" } }, "mac" : { stage( "install" ) {echo "installing in mac" } stage( "test" ) {echo "testing in mac" } } ]) } stage( "cleanup" ) {echo "cleanup" } scripted parallel within declarative pipeline pipeline { agent( "none" ) stages { stage( "prepare" ) {steps {echo "prepare" }} stage( "build" ) {steps {echo "build" }} stage( "test" ) { steps { script { parallel ([ "linux" : { stage( "install" ) {echo "installing in linux" } stage( "test" ) {echo "testing in linux" } }, "windows" : { stage( "install" ) {echo "installing in windows" } stage( "test" ) {echo "testing in windows" } }, "mac" : { stage( "install" ) {echo "installing in mac" } stage( "test" ) {echo "testing in mac" } } ]) } } } stage( "cleanup" ) {steps {echo "cleanup" }} } }  

          Alberto added a comment -

          I have the same problem mentioned by betoz. With a scripted pipeline inside a declarative one, BlueOcean gets confused.
          \

          I am using a scripted pipeline inside a declarative one because I need to spawn multiple parallel jobs according to some dynamic variables. Using Matrix/Axes I cannot do it.

          Alberto added a comment - I have the same problem mentioned by betoz . With a scripted pipeline inside a declarative one, BlueOcean gets confused. \ I am using a scripted pipeline inside a declarative one because I need to spawn multiple parallel jobs according to some dynamic variables. Using Matrix/Axes I cannot do it.

          Jason added a comment -

          Is there any update on this ticket?

          Jason added a comment - Is there any update on this ticket?

          Mike added a comment -

          Seeing the same thing.  Is there a workaround or status update?

          Mike added a comment - Seeing the same thing.  Is there a workaround or status update?

          Darius added a comment -

          You can add an empty stage as a workaround

          "linux": {
              stage("linux") {} // workaround for https://issues.jenkins.io/browse/JENKINS-55438
              stage("install") {echo "installing in linux"}
              stage("test") {echo "testing in linux"}
          }, 

           

          Darius added a comment - You can add an empty stage as a workaround "linux" : { stage( "linux" ) {} // workaround for https://issues.jenkins.io/browse/JENKINS-55438    stage( "install" ) {echo "installing in linux" }   stage( "test" ) {echo "testing in linux" } },  

            Unassigned Unassigned
            acarr468 Adam Carroll
            Votes:
            33 Vote for this issue
            Watchers:
            38 Start watching this issue

              Created:
              Updated: