Build flow "build" function doesn't return a build object if FAILED or UNSTABLE

46 views
Skip to first unread message

Valeriy Leykin

unread,
Dec 1, 2015, 8:17:38 AM12/1/15
to Jenkins Users
Hi,

I'm using the build flow in my jobs and I would like to get any build result from build object even if the build is failed or unstable.
For example:

try{
    BUILD_TO_RETURN
= build(parameters: newparams, job: jobName, quietPeriod: 5);
    println
("Result is: " + BUILD_TO_RETURN.getResult());  // THIS LINE IS NOT BEING CALLED IF THE BUILD IS UNSTABLE
}
catch(Exception e)
{
   if (e instanceof InterruptedException || e.getCause() instanceof InterruptedException) {
      throw e;
   }
   else if( e.toString().contains("UNSTABLE") || e.toString().contains("FAILURE")){
       println("buildJob : No exception, the job result: ${e}"); // THIS LINE IS BEING CALLED
       return BUILD_TO_RETURN;

      }


What actually happening is that BUILD_TO_RETURN returned is null. Which means an exception was thrown for UNSTABLE build.
I would like rather to have the UNSTABLE build object in my hands and return it.

Is it possible to "ignore" failure\unstable build and do not ignore all other exceptions?

Thanks,
Valeriy

Christopher Orr

unread,
Dec 1, 2015, 7:41:12 PM12/1/15
to jenkins...@googlegroups.com
Hi there,

On 01/12/15 14:17, Valeriy Leykin wrote:
> I'm using the build flow in my jobs and I would like to get any build
> result from build object even if the build is failed or unstable.

I haven't used Build Flow, but I would guess that this is a basic
scoping problem.

BUILD_TO_RETURN is defined in the "try" block, which means it's not
visible outside of that block, i.e. it won't exist and so returns `null`
when the "catch" block tries to access it.

Try defining your variable before the "try" block:

def BUILD_TO_RETURN
try {
BUILD_TO_RETURN = build(...)
} catch (...) {
...
}

Regards,
Chris

Valeriy Leykin

unread,
Dec 3, 2015, 4:51:06 AM12/3/15
to Jenkins Users
Hi Christofer,

Actually this is exactly what is written aline before (def BUILD_TO_RETURN).
The problem is that when build is UNSTABLE or FAILED exception is being thrown without returning from the build method.

Regards,
Valeriy

Stefan Thomasson

unread,
Dec 3, 2015, 3:26:42 PM12/3/15
to jenkins...@googlegroups.com
Hi,
From my experience Build flow do not throw an exception if the build is aborted, unstable or failed, assuming the build actually started and completed normally.

I assume you have checked what exception was caught.
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/fb03e2e7-4f4d-457b-a0f7-74db03a09915%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages