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 <[email protected]> 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 [email protected]. > 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVcpNOzJnS0GEktkFaONiHHOfFFfdB6LBJZmkBrB14JYzg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
