Details
-
Bug
-
Status: Open (View Workflow)
-
Minor
-
Resolution: Unresolved
-
None
-
Jenkins version 2.89.3
pipeline-model-definition-plugin 1.2.7
Description
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 } } } }
This sounds somewhat related to an issue i am seeing. Perhaps you can advise abayer?
I want to call some shell commands to set env vars based on other env vars, and when they are cross-referenced, they appear to get re-evaluated. Here is a basic example just using uuidgen - the use case is that the command setting SHARED_VALUE is not idempotent:
Is this expected behaviour? i have not found a workaround, so have reverted to a bash script in the step instead.