jenkinsjenkins-pipelinejenkins-groovy

How to enforce the 2nd job session in the waiting list in jenkins job


I have a jenkins job that is in such configuration:

    pipeline { 
        agent any 
        ...         
        
        stages {
          stage('Set-Up'}
             script { ... }
          }
          
          stage('Jobs') {
             parallel {
                stage('job-1') { 
                  steps { ... } 
                }
                stage('job-2') {
                  steps { ... }
                }
            }   // end of parallel 
          } //  end of Jobs
       } // end of stages 
       
       post {
          always {
             // generate allure report 
                ... 
             // Send email with the Allure report attached
                emailext(
                    body: '''${SCRIPT, template="allure-report.groovy"}''',
                    subject: "Jenkins Job '${env.JOB_NAME}--${env.BUILD_NUMBER}'  ${currentBuild.currentResult}",
                    to: params.receiver, 
                    mimeType: 'text/html')
             }  // end of always. 
     }  // end of Post 
}  // end of the pipeline 

The issue I am hitting is, if the 1st job session still in process, and the 2nd job session starts, the 2nd job session fails instantly. It will not be in the waiting list till the 1st job session ends.

And the 2nd failed job session sends such message in the email:

Groovy Template file [allure-report.groovy] was not found in $JENKINS_HOME/email-templates.

Is there a way to enforce that ?

Thanks,

Jack


Solution

  • What makes the job-2 stage start before the job-1 stage is still in process is this keyword:

                 parallel {
                     ...
                 }
    

    If you want the job-2 stage to wait for the job-1 stage to finish before it runs you can remove the parallel block and go back to the default, sequential execution of stages.