Home > Mobile >  Jenkins Declarative Pipeline Non Critical Path Stage
Jenkins Declarative Pipeline Non Critical Path Stage

Time:08-16

I have a declarative pipeline and I'd like to be able to mark some steps as essentially not being on the critical path. Taking the below simplified example, I would like Job B and Job C to be part of the overall process, but I don't want job D to be dependent on them, and allow failures to be handled without failing the rest of the pipeline. Job A takes the most time, and running B and C at this time minimizes the overall length the process runs for.

Being explicit, nothing should depend on B and C, but I want them to run as part of Stage 1. Job D should depend on Job A. Essentially I would like the pipeline to run Jobs B and C and then not care about them once they are kicked off

 pipeline {
  stages {
    stage('Stage 1 Name') {
      parallel{
        stage('Stage 1 parallel A'){
          steps {
            build 'Job A'
          }
        }
        stage('Stage 1 parallel B') {
          steps {
            build 'Job B'
          }
        }
        stage('Stage 1 parallel C') {
          steps {
            build 'Job C'
          }
        }
      }
    }  
    stage('Stage 2') {
      steps {
        build 'Job D'
      }
    }
    stage('Stage 3 Name') {
      parallel{
        stage('Stage 3 parallel A'){
          steps {
            build 'Job F'
          }
        }
        stage('Stage 3 parallel B') {
          steps {
            build 'Job E'
          }
        }
      }
    } 
  }
}

CodePudding user response:

Have you considered using wait: false for the build step?

wait : boolean (optional)

If true, the pipeline will wait for the result of the build step before jumping to the next step. Defaults to true.

-- https://www.jenkins.io/doc/pipeline/steps/pipeline-build-step/#build-build-a-job

pipeline {
  stages {
    stage('Stage 1 Name') {
      parallel{
        stage('Stage 1 parallel A'){
          steps {
            build 'Job A'
          }
        }
        stage('Stage 1 parallel B') {
          steps {
            build(job: 'Job B', wait: false)
          }
        }
        stage('Stage 1 parallel C') {
          steps {
            build(job: 'Job C', wait: false)
          }
        }
      }
    }
    // ...
  • Related