thanks, that seems to make sense with what i am noticing. Seems like the
root cause is that, the variable is not assigned if the 'shell' step fails
/ non 0 exit status.
i am trying to assign the variable with the shell scripts stdout. I would
like to capture the stacktract so that it prints the shell scripts
stdout/stderr in the mail, rather than the generic "'hudson.AbortException:
script returned exit code 1'"


On Mon, Aug 28, 2017 at 2:32 PM, Slide <slide.o....@gmail.com> wrote:

> You don't need to initialize to null outside the try, just "def val_log"
> is fine. I've used this in my pipeline and it works fine. Can you verify
> that your pipeline is getting to the point where val_log is assigned, and
> also verify it's not assigned anywhere else?
>
> On Mon, Aug 28, 2017 at 12:23 PM niristotle okram <nirish.ok...@gmail.com>
> wrote:
>
>>
>>
>> down votefavorite
>> <https://stackoverflow.com/questions/45924945/scoping-of-a-groovy-variable-inside-a-closure-in-try-to-access-from-catch#>
>>
>> how do i access the value of a variable assigned inside a closure within
>> a try() in the catch() statement. here is what i am trying to achieve but i
>> keep getting the initialization value that i assigned.
>>
>> node('linux') {
>>
>>         def val_log = null;
>>
>>     try{
>>
>>         stage('abc') {
>>
>>         val_log = //some steps that generates a log that i want
>>
>>         }
>>
>>         println '$val_log'  //this works
>>
>>     }
>>
>>     catch(err)
>>         stage('mail') {
>>         // code to send email notification with '$val_log'
>>         //--> the $val_log returns 'null' and not the
>>         //value assigned in the try() part.
>>         }}
>>
>> Is there a way, to get the value for the variable inside the catch()
>> statement.
>>
>> Thank you...
>>
>>
>>
>> --
>> 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-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/jenkinsci-users/CAPzcO4iK8F4vJ_D-0n2Gpnxph99Km9RCFQ52jtj9OqKY-
>> E7K-Q%40mail.gmail.com
>> <https://groups.google.com/d/msgid/jenkinsci-users/CAPzcO4iK8F4vJ_D-0n2Gpnxph99Km9RCFQ52jtj9OqKY-E7K-Q%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> 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-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/jenkinsci-users/CAPiUgVcpNOzJnS0GEktkFaONiHHOf
> FFfdB6LBJZmkBrB14JYzg%40mail.gmail.com
> <https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVcpNOzJnS0GEktkFaONiHHOfFFfdB6LBJZmkBrB14JYzg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Regards
nirish okram

-- 
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-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/CAPzcO4g753cF1T%3DOPi%3Da26F%3DFkGxf75tKKs005LV5pg2iTdvAA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to