Reputation: 625
I am trying to execute multiple windows batch commands in jenkins one after the other. The problem is that if any the of the project/build fails, it never gonna execute next windows batch commands.
My question is How to execute next windows batch command if previous execution fails?
Help me with this regard.
Upvotes: 4
Views: 5986
Reputation: 27505
When you say "multiple windows batch commands", do you mean:
If configuring multiple build steps, you just need to make sure that the last command of the build step does not return anything other than 0
. You can do this by adding either of the following as the very last statement in your build step:
exit /b 0
echo "All done"
As for multiple lines within the same build step, default implementation of Execute Windows Batch Command does not break if one line/statement fails (which is different from default Execute Shell implementation). As long as the very last statement returns 0
, the build step will not fail, and any lines failing in between does not matter.
Once again, you can reference to the above list to make sure that the last line always returns 0
Upvotes: 1
Reputation: 14772
Re "if any the of the project/build fails"
Do you mean "if any of the batch commands fails"?
See Conditional BuildStep Plugin.
In your job config scroll down to:
Build
[ For each command that can fail Add build step at the bottom of this Build section ]
Conditional step (single)
Run? | Not
! | Execute Windows batch commands
Commands | ... your commands ...
[ Click Advanced... ]
On evaluation failure | Fail the build
Builder | Set the build result
Result | Success
Or add just one Conditional step (single) section and write all of your commands into:
Commands | ... your commands ...
Or maybe Conditional step (multiple) is the way to go for you. I haven't used this so far, so I'm not much of a help there.
Upvotes: 0