0

I am trying to do some loop with sshPublisher.
I have to catch failed iteration from the loop.

For example,

array = [some configs]
array.each {
    sshPublisher ( exec some command )
    if ( error occurred from sshPublisher) { do something }
}  

I found that if an error occurred in sshPublisher, it changes currentBuild.result to UNSTABLE,

So I tried for using currentBuild.result, but it can't be set from UNSTABLE to SUCCESS, so I can't use this.

Is there anyway to get error code or something from the sshPublisher()?

hakamairi
  • 4,464
  • 4
  • 30
  • 53
Jiho
  • 338
  • 1
  • 6
  • 14

1 Answers1

2

That's an old plugin, with latest release from 2016.

The design is too coupled to the build result itself to just read it out, here's the documentation on the options

Fail the build if an error occurs

By default, when an error occurs, the publisher will set the build result to UNSTABLE. Setting this option will cause a failure in the publisher to set the build result to FAILED. This option is especially useful in the case of a promotion where the main action is to Publish Over ...

What you could do is check current build result in your loop and reset it if on unstable/failure, like

if ('FAILURE'.eqauls(currentBuild.result)) {
    //do your thing
    currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS
}
hakamairi
  • 4,464
  • 4
  • 30
  • 53
  • Thanks for your answer. But 'currentBuild.result = "SUCCESS"' is not work, due to the design.. (https://stackoverflow.com/questions/38221836/how-to-manipulate-the-build-result-of-a-jenkins-pipeline-job) Could you suggest me any other plugin to replace sshPublisher..? – Jiho Apr 09 '19 at 08:03
  • I've updated my answer with a code that should work. You probably need some approvals to run this though. As for recommendations - what's your use case? – hakamairi Apr 09 '19 at 08:25
  • Thanks! I'll try that. I just worried that this requires some approvals and I'm not sure whether it is ok to use or not.. – Jiho Apr 10 '19 at 01:44
  • I'm trying to deploy jar file to several sever in parallel. And if some fail to deploy, run rollback script for only that failed ones on the next stage. (I want to divide a deploy stage and a rollback stage) – Jiho Apr 10 '19 at 01:44
  • I tried 'currentBuild.rawBuild.@result = hudson.model.Result.SUCCESS' and it succeed. Thanks a lot! – Jiho Apr 10 '19 at 03:59
  • Glad to help :) – hakamairi Apr 10 '19 at 06:05