4
votes

I have a jenkins setup with a bunch of pipelines. I wrote a new pipeline which can start all pipelines at once. I would like to build other stages, even if one of them fails.

The script currently looks like this

stage 'CentOS6'
build 'centos6.testing'

stage 'CentOS7'
build 'centos7.testing'

stage 'Debian7'
build 'debian7-x64.testing'

stage 'Debian8'
build 'debian8-x64.testing'

The build scripts itself contain the node they should run on.

How can the script continue with the following stages even if one of them fails.

Cheers

3
Can't you use try-catch? Similar to this answer: stackoverflow.com/questions/40896729/… - MaTePe
yes I could, but this would also mark unsuccessfull builds as successfull - raddirad
Should they be run in parallell or in a sequence? - MaTePe
they should run in parallel - raddirad
try-catch will work nicely as @MaTePe says. If you want to mark the stages as failed, then have a look at this question stackoverflow.com/questions/36852310/… - vaza

3 Answers

2
votes

If you use the parallel step, this should work as you expect by default, as the failFast option, which aborts the job if any of the parallel branches fail, defaults to false.

For example:

parallel(
    centos6: { build 'centos6.testing' },
    centos7: { build 'centos7.testing' },
    debian7: { build 'debian7-x64.testing' },
    debian8: { build 'debian8-x64.testing' }
)
5
votes

If they should be run in a sequence you can do something like this:

def buildResult= 'success'
try{
  build 'centos6.testing'
}catch(e){
   buildResult = 'failure'
}
currentBuild.result = buildResult

If they should be run in parallell you just run them: https://www.cloudbees.com/blog/parallelism-and-distributed-builds-jenkins

0
votes

What worked for me:

    'Task' : {
        build( job : "DemoJob-2", wait: false )
        build( job : "DemoJob-3", wait: false )
    }