2

Problem:

Depending on my script in my Jenkins task, I sometime wants to quit the task marked as successful in the middle of a code section. Is that possible?

I tried using exit code in script, but that doesn't exit Jenkins.

Cher
  • 2,789
  • 10
  • 37
  • 64

2 Answers2

3

Yes it is possible you could use exit 0 - success exit 1 - failed(or any other number)

dmr
  • 526
  • 2
  • 8
0

Id depends on how much call levels you currently on. Try executing several exit commands like:

exit 0 exit 0 ...so on

Alternatively see Is there a way to write a bash function which aborts the whole execution, no matter how it is called? . There should be a way to kill process with a successiful return code.

One more reference: https://serverfault.com/questions/390846/kill-a-process-and-force-it-to-return-0-in-linux

Community
  • 1
  • 1
Zloj
  • 2,235
  • 2
  • 18
  • 28
  • thanks!! However I'm in a Jenkins environment, it did not work. I'm actually able to exit the batch, but then Jenkins execute other steps which I want to skip. – Cher Jul 30 '15 at 14:11
  • 1
    You want to use https://wiki.jenkins-ci.org/display/JENKINS/Conditional+BuildStep+Plugin then. Just split your job to logical parts and then define some variable, which based on results will be used to indicate whether or not do you want to perform the next steps. – Zloj Jul 31 '15 at 13:17