4

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

Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
raddirad
  • 331
  • 1
  • 8
  • 17
  • 1
    Can't you use try-catch? Similar to this answer: http://stackoverflow.com/questions/40896729/jenkins-continuous-delivery-pipeline-skip-stage-based-on-input/40907739#40907739 – MaTePe Dec 08 '16 at 12:25
  • yes I could, but this would also mark unsuccessfull builds as successfull – raddirad Dec 08 '16 at 12:47
  • Should they be run in parallell or in a sequence? – MaTePe Dec 08 '16 at 13:17
  • they should run in parallel – raddirad Dec 08 '16 at 13:24
  • try-catch will work nicely as @MaTePe says. If you want to mark the stages as failed, then have a look at this question https://stackoverflow.com/questions/36852310/show-a-jenkins-pipeline-stage-as-failed-without-failing-the-whole-job/42147678#42147678 – vaza Feb 23 '18 at 09:52

3 Answers3

5

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

MaTePe
  • 936
  • 1
  • 6
  • 11
2

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' }
)
Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
  • And how to make job fail as soon as one of the parallel builds fails? – azizbekian Mar 02 '17 at 09:56
  • @azizbekian Add a `failFast: true` branch to the `parallel` block. – Christopher Orr Mar 05 '17 at 12:17
  • Thanks! Will try that! Will you please also see my [this](http://stackoverflow.com/questions/42588457/connectedandroidtest-on-multiple-emulators) question, I hope you can help there too, because it's more or less concerned to the same topic. – azizbekian Mar 05 '17 at 12:19
0

What worked for me:

    'Task' : {
        build( job : "DemoJob-2", wait: false )
        build( job : "DemoJob-3", wait: false )
    }
lenkovi
  • 1,708
  • 2
  • 11
  • 16