Hi - I have an issue with variables being restored in a pipeline job after a Jenkins restart.
Say I have a pipeline like this: // Local var set to 'env' def localEnv = env // Simple local var def foo = "Bar" pipeline { agent any environment { // You can do it here but I really want the whole env in my own var myBuildNumber = "${env.BUILD_NUMBER}" } stages { stage('Init') { steps { echo "${localEnv.BUILD_NUMBER}" } } stage('Hello') { steps { echo "hello" input 'Waiting for input...' // Lets see what we have echo "localEnv.BUILD_NUMBER = ${localEnv.BUILD_NUMBER}" echo "env.BUILD_NUMBER = ${env.BUILD_NUMBER}" echo "foo = ${foo}" echo "myBuildNumber = ${myBuildNumber}" } } } } I am making my own local variable as copy of the 'env' variable (localEnv). I do this a lot in my jobs because I call custom library DSL-type structure similar to this: myCustomThing { reference = localEnv.BUILD_NUMBER message = "Something about build ${localEnv.BUILD_NUMBER}" } If I use 'env' there, I get a null pointer exception on this closure - something to do with groovy Closure delegate (that is another question I guess), so I did this 'def localEnv = env' thing to get around that. Anyway, for the normal case my job above outputs this after selecting approve on the input and all is well: Waiting for input... Proceed <http://localhost:32779/job/Foo/21/console#> or Abort <http://localhost:32779/job/Foo/21/console#> Approved by Bill Dennis <http://localhost:32779/user/bill> [Pipeline] echo localEnv.BUILD_NUMBER = 21 [Pipeline] echo env.BUILD_NUMBER = 21 [Pipeline] echo foo = Bar [Pipeline] echo myBuildNumber = 21 When I restart Jenkins while the input is waiting then approve the input the output is like this (note the null): Waiting for input... Proceed <http://localhost:32781/job/Foo/22/console#> or Abort <http://localhost:32781/job/Foo/22/console#> Resuming build at Mon Mar 27 23:48:21 UTC 2017 after Jenkins restart Ready to run at Mon Mar 27 23:48:32 UTC 2017 Approved by Bill Dennis <http://localhost:32781/user/bill> [Pipeline] echo localEnv.BUILD_NUMBER = null [Pipeline] echo env.BUILD_NUMBER = 22 [Pipeline] echo foo = Bar As can be seen, 'localEnv.BUILD_NUMBER' comes back as *null* after the Jenkins restart. So it looks like I need to do a deep-copy of the 'env' or set up many more variables in my environment section for everything that needs to be available from 'env' surviving a restart, so that things I need cans be passed to any of my shared library stuff. Does anyone have any deeper understanding of this? Thanks, --Bill -- 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/8aa04dac-5299-4d08-ba59-3a1a816c606c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.