What is the order of execution of jobs in a Jenkins pipeline?

Viewed 36

I have a pipeline with multiple jobs inside it, but I'm facing a dilemma. What is the order of execution of the jobs inside the pipeline? Is it the order from the script? The reason I'm interested is because I want JOB1 to run at the beginning of the pipeline and somewhere in the middle. However, when the pipeline is running JOB1 in the beginning for whatever reason it runs twice in succession. Is there a particular reason for that or am I missing something?

    pipeline {
    agent any;
    options {
        timeout(time: 4, unit: 'HOURS')
    }
    stages {
        stage('All tests in parallel') 
        {
            parallel 
            {
                stage('JOB1') {
                    steps {

                        callJobByName("JOB1")
                    }
                }
                stage('JOB2') {
                    steps {
                        callJobByName("JOB2")
                    }
                }
                stage('JOB1') {
                    steps {
                        callJobByName("JOB1")
                    }
                }
                stage('JOB3') {
                    steps {
                        callJobByName("JOB3")
                    }
                }
            }
        }
    }
}
1 Answers

As per the pipeline above, every Stage within the parallel block will run in parallel. So you can't guarantee an order. If you want to execute them in order, remove the parallel block. Then the Stages will execute in the order they are defined. If you just want to JOB1 to execute first and then to execute others and JOB1 again in parallel, you can simply move the first stage out from the parallel block.

pipeline {
agent any;
options {
    timeout(time: 4, unit: 'HOURS')
}
stages {
    stage('All tests in parallel') 
    {
        stage('JOB1') {
          steps {

              callJobByName("JOB1")
          }
        }
        parallel 
        {
            stage('JOB2') {
                steps {
                    callJobByName("JOB2")
                }
            }
            stage('JOB1') {
                steps {
                    callJobByName("JOB1")
                }
            }
            stage('JOB3') {
                steps {
                    callJobByName("JOB3")
                }
            }
        }
    }
}
}
Related