-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
Jenkins version 2.89.3
pipeline-model-definition-plugin 1.2.7
Functions that are called from within the environment block do not have access to environment variables that are defined previously in the same environment block. Parameters work as expected and accessing the function outside of the environment block works as expected.
Example pipeline that exhibits the null environment variable function
#!/usr/bin/env groovy def returnEnvVar() { env.VARIABLE } pipeline { environment { VARIABLE = "I'm set" COPY_VARIABLE = returnEnvVar() // this gets set to null } stages { stage('Print Environment') { steps { echo "${VARIABLE}" echo "${COPY_VARIABLE}" // this prints out null } } } }
Yeah, that's expected - environment variable resolution is an annoyingly complicated thing, but the gist is that we resolve the values before any of them are added to env, and then add all of them to env together. You can reference one variable in another (i.e., in this case, COPY_VARIABLE = VARIABLE would work) because the resolution process knows to look for references to one of the variables in the value for another, but the referenced variable has to be referenced explicitly, not indirectly via a method.