// 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}"
}
}
}
}myCustomThing {
reference = localEnv.BUILD_NUMBER
message = "Something about build ${localEnv.BUILD_NUMBER}"
}Waiting for input...
Approved by Bill Dennis
[Pipeline] echo
localEnv.BUILD_NUMBER = 21
[Pipeline] echo
env.BUILD_NUMBER = 21
[Pipeline] echo
foo = Bar
[Pipeline] echo
myBuildNumber = 21
Waiting for input...
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
[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