Abort a job as soon as an error message appears in the console output

20 views
Skip to first unread message

Patricia Mendez Lorenzo

unread,
Nov 13, 2015, 10:16:46 AM11/13/15
to jenkins...@googlegroups.com

Dear all,

i have a set of jenkins jobs with some bash code included in the "Execute shell" window. The primary bash execution calls some scripts that at the same time call some other scripts... this means; there is a set of children and subchildren and sub-subchildren even. I would like to ensure that as soon as a sub-child fails, the whole jenkins job is aborted.

The option "set -e" is not recursive, so I will have to add it to each sub-parent, this makes the whole chain quite inflexible. At a certain moment we will surely forget the "set -e" option.

Is there any plug-in or solution for this?. what i would like is that as soon as an ERROR appears in the console output, the build gets just aborted at that point.

Thanks a lot!
Patricia

Victor Martinez

unread,
Nov 13, 2015, 11:17:24 AM11/13/15
to Jenkins Users
Hi,

If I understood correctly you could add the below shebang in each script file

#!/bin/bash -xe

Then in case of any errors of those children scripts will be trapped accordingly. you might need to review whether you use any traps


I hope it helps

Cheers

Patricia Mendez Lorenzo

unread,
Nov 16, 2015, 4:21:46 AM11/16/15
to Jenkins Users
Thanks a lot Victor for your answer.

In any case, this is what we would like to avoid. At a certain point, when the chain of scripts is too long, we will certainly forget to include the -e option. This is not a robust approach. I was wondering in Jenkins is able to do it as toolkit, other tools are able to do it (as electric commander). You should not care about the error tracking; the tool should be able to do it for you

Cheers
Patricia

Victor Martinez

unread,
Nov 16, 2015, 5:21:11 AM11/16/15
to Jenkins Users
Hi again,

  Jenkins run the above shebang by default:

   But if you run scripts and other scripts without trapping those errors then IMO the root cause is basically in the scripts itself, so if those scripts don't handle those errorlevels accordingly then you won't be able to track those error, I'm afraid I don't know how electric commander works, but jenkins does solve those error tracking accordingly and generally, but for specific cases error tracking should be, IMO, managed by the scripts rather than any tools, but this is another topic out of this thread.

   Using shell scripts for building/testing/compiling are a kind of non-standard way of doing automatic tasks, if you use gradle/maven/ant/nant/.... then those errorlevels will be managed accordingly. It's not a trivial change for old legacy systems, but that's probably something else.

  Let's see if someone else can provide another way of solving it.

Cheers
Reply all
Reply to author
Forward
0 new messages