Creating a sequential step in a jenkins declarative pipeline preceding a parallel stage

Viewed 6956

I would like to setup parallel stages as described in the image

In this instance, the setup is pretty heavy so has to be done once before the parallel group starts of G1, G2 and G3. At the same time, the stage : Initial Checks has 2 items that I would like to run in parallel.

Is this possible in the Declarative Pipeline or do I have to resort to a script?

I couldnt see in the documentation the ability for this to work

Stages {
    stage ('P1') {
    }
    stage ('P2 Setup') {}
    stage ('P2') {
    //Here it can contain either Steps or Parallel. I can only do
       parallel {
          stage ('g1') {} //Parallel tests
          stage ('g2') {}
          stage ('g3') {}
       }
    }
    stage ('P2 Cleanup') {}
}

Have you encountered similar situations and what have your solutions been like?

Ofcourse 1 solution is to make Setup and Cleanup as part of every group, but like I said, its pretty intensive and I would only take it on if what the diagram indicates isn't possible.

Solution 2

 stage ('p2') {
    script {
      //Some scripting here to get the result?

    }
 }

Pipeline

2 Answers

This is not supported by a DSL or declarative pipeline yet. You are essentially looking for nested parallel stages as mentioned here

Issue is still open with Jenkins community which you can watch here

In your given case, you can launch stage P1 and stage setup in parallel. However, it is important to start P1 as a background process because from your graph it appears that P1 is a time-intensive operation. Once group stage completes, you can collect the status of P1 and proceed to S2.

stages{
   stage('Build'){
        steps{
              echo "Build"
         }
     }
   stage('Init'){
        parallel{
             stage('P1'){steps{ echo "launch p1 in background"}}
             stage('setup'){steps{echo "setup"}}
           }
     }
   stage('Group'){
        parallel{
             stage('P1'){steps{echo "p1"}}
             stage('P2'){steps{echo "p2"}}
             stage('P3'){steps{echo "p3"}}
           }
     }
   stage('Cleanup'){
        steps{
              echo "cleanup"
         }
     }
   stage('Check P1 status'){
        steps{
              echo "Check"
         }
     }
  stage('S2'){
        steps{
              echo "S2"
         }
     }
}

Output will look like thi

I think you are looking for this

  node {
        stage("P1"){}
        stage("p2") {}
        stage("p3") {
          parallel (
                "firstTask" : {

                },
                "secondTask" : {

               }
            )
        }

    }
Related