Answers: <p>This was covered in an <a href="https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/" rel="nofollow noreferrer">official blog post</a> when the feature to nest stages inside a parallel block was added.</p>
  
  <p>Here is the example copy-pasted from the blog post.  In this example, the Windows and Linux blocks are run in parallel, but the stages within each block are run sequentially:</p>
  
  <pre><code>pipeline {
      agent none
  
      stages {
          stage("build and deploy on Windows and Linux") {
              parallel {
                  stage("windows") {
                      agent {
                          label "windows"
                      }
                      stages {
                          stage("build") {
                              steps {
                                  bat "run-build.bat"
                              }
                          }
                          stage("deploy") {
                              when {
                                  branch "master"
                              }
                              steps {
                                  bat "run-deploy.bat"
                              }
                          }
                      }
                  }
  
                  stage("linux") {
                      agent {
                          label "linux"
                      }
                      stages {
                          stage("build") {
                              steps {
                                  sh "./run-build.sh"
                              }
                          }
                          stage("deploy") {
                               when {
                                   branch "master"
                               }
                               steps {
                                  sh "./run-deploy.sh"
                              }
                          }
                      }
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>EDIT: I missed that you're trying to do this based on arbitrary input.  If you want to do that, you must use scripted Pipelines (or a script nested in a Declarative Pipeline).  Plain Declarative Pipelines don't support that kind of runtime-defined Pipelines.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-05-21T10:34:57.477Z
Answers: Even in the case of scripted pipeline, is it possible to have nested inside parallel. The parallel accepts Map<String, closure> . I need like Map<String, closure<inner stages>>
Answers: june
Answers: CC BY-SA 4.0
Answers: 2019-05-21T16:14:40.363Z
Answers: Yes, it is possible.  I've done it several times and there are a few questions on this site about that topic.  A closure is an arbitrary block of code so you can put anything you want in it, including stage definitions.
Answers: jayhendren
Answers: CC BY-SA 4.0
Answers: 2019-05-24T12:29:25.920Z
Answers: Can you share a piece of code?
Answers: june
Answers: CC BY-SA 4.0
Answers: 2019-05-20T22:01:21.123Z
Answers: 2019-05-20T22:01:21.123Z
Answers: jayhendren
Body: <p>I'm trying to write a declarative pipeline code that accepts a map and create a pipeline. I can able to achieve sequential stages or parallel stages but facing problems while making a pipeline that contains sequential stages inside parallel stages.</p>
  
  <p>The input data would be Map. Each list in the map should run parallel and the items inside the list corresponding to each key should run in sequentially.</p>
  
  <p>example data : [1:[11,12], 2:[21,22], 3:[31,32]]</p>
  
  <p>Am using Jenkins 2.164.3</p>
  
  <p>The output should be </p>
  
  <p><a href="https://i.sstatic.net/QOt6c.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QOt6c.jpg" alt="enter image description here"></a></p>
  
Tags: <jenkins-pipeline><jenkinsfile>
Title: How to write a dynamic declarative pipeline that contains sequential job inside parallel job
UserDisplayName: june
ThreadText: # How to write a dynamic declarative pipeline that contains sequential job inside parallel job
  
  (Asked by: username_0 on 2019-05-18)
  
  I'm trying to write a declarative pipeline code that accepts a map and create a pipeline. I can able to achieve sequential stages or parallel stages but facing problems while making a pipeline that contains sequential stages inside parallel stages.
  
  The input data would be Map. Each list in the map should run parallel and the items inside the list corresponding to each key should run in sequentially.
  
  example data : [1:[11,12], 2:[21,22], 3:[31,32]]
  
  Am using Jenkins 2.164.3
  
  The output should be
  
  [![enter image description here](https://i.sstatic.net/QOt6c.jpg)](https://i.sstatic.net/QOt6c.jpg)
  
  **Tags:** jenkins-pipeline, jenkinsfile
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-05-20. Score: 2
  
  This was covered in an [official blog post](https://jenkins.io/blog/2018/07/02/whats-new-declarative-piepline-13x-sequential-stages/) when the feature to nest stages inside a parallel block was added.
  
  Here is the example copy-pasted from the blog post. In this example, the Windows and Linux blocks are run in parallel, but the stages within each block are run sequentially:
  
  ```
  pipeline {
      agent none
  
      stages {
          stage("build and deploy on Windows and Linux") {
              parallel {
                  stage("windows") {
                      agent {
                          label "windows"
                      }
                      stages {
                          stage("build") {
                              steps {
                                  bat "run-build.bat"
                              }
                          }
                          stage("deploy") {
                              when {
                                  branch "master"
                              }
                              steps {
                                  bat "run-deploy.bat"
                              }
                          }
                      }
                  }
  
                  stage("linux") {
                      agent {
                          label "linux"
                      }
                      stages {
                          stage("build") {
                              steps {
                                  sh "./run-build.sh"
                              }
                          }
                          stage("deploy") {
                               when {
                                   branch "master"
                               }
                               steps {
                                  sh "./run-deploy.sh"
                              }
                          }
                      }
                  }
              }
          }
      }
  }
  
  ```
  
  EDIT: I missed that you're trying to do this based on arbitrary input. If you want to do that, you must use scripted Pipelines (or a script nested in a Declarative Pipeline). Plain Declarative Pipelines don't support that kind of runtime-defined Pipelines.
  
  > **Comments:**
  > **username_0**: Even in the case of scripted pipeline, is it possible to have nested inside parallel. The parallel accepts Map<String, closure> . I need like Map<String, closure<inner stages>>  
  > **username_1**: Yes, it is possible.  I've done it several times and there are a few questions on this site about that topic.  A closure is an arbitrary block of code so you can put anything you want in it, including stage definitions.  
  > **username_0**: Can you share a piece of code?  
  
  ---
  
  