Jenkins parallel jobs - trigger another job if atleast one success (like successFast) - don't wait for all job's result

Viewed 440

I am able to run the parallel Jenkins jobs using parallel syntax and able to get the result back of each child job using wait: true and propagate: false.

example -

pipeline {
stages {
    stage('Parallel Jobs'){
        steps{
            script{
                def result = parallel(
                        "JobAKey":{
                            build job: "job-A", wait: true, propagate: false, parameters: [string(name: 'param1', value: val1)]
                        },
                        "JobBKey":{
                            build job: "job-B", wait: true, propagate: false, parameters: [string(name: 'param1', value: val1)]
                        }
                    )
                    print(result['JobAKey'].result)
                    print(result['JobBKey'].result)
                    if (result['JobAKey'].result == 'SUCCESS' || result['JobBKey'].result == 'SUCCESS') {
                        build job: "job-C", wait: false, parameters: [string(name: 'param2', value: val2)]
                        build job: "job-D", wait: false, parameters: [string(name: 'param2', value: val2))]
                    }
                }
            }
        }
    }
}

I want to run job-C and job-D if any of one job job-A or job-B returns SUCCESS. If job-B returns SUCCESS quickly then I don't want to wait for job-A to complete (SUCCESS / FAILURE) or vice versa. I don't know which job is going to finish quickly and going to return SUCCESS.

With "wait: True", parallel waits for both jobs to finish and then it starts job-C and job-D.

Is there something like successFast (like failFast) ?

Condition is, any one job from list of parallel jobs should return SUCCESS on completion so that we can start next jobs (job-C and job-D).

Thanks in advance!

0 Answers
Related