This question follows from reading How to list all `env` properties within jenkins pipeline job?.
This answer to the linked question offers this solution that iterates through each element in env.getEnvironment()
:
env.getEnvironment().each { name, value -> println "Name: $name -> Value $value" }
In my case, the output is:
Name: BUILD_DISPLAY_NAME -> Value #106
Name: BUILD_ID -> Value 106
Name: BUILD_NUMBER -> Value 106
Name: BUILD_TAG -> Value jenkins-wip-106
Name: BUILD_URL -> Value http://jenkins-server:8080/job/wip/106/
Name: CI -> Value true
Name: CLASSPATH -> Value
Name: HUDSON_HOME -> Value /var/lib/jenkins
Name: HUDSON_SERVER_COOKIE -> Value 15bd679c60fb6abe
Name: HUDSON_URL -> Value http://jenkins-server:8080/
Name: JENKINS_HOME -> Value /var/lib/jenkins
Name: JENKINS_SERVER_COOKIE -> Value 19bd670c60fb6bbe
Name: JENKINS_URL -> Value http://jenkins-server:8080/
Name: JOB_BASE_NAME -> Value wip
Name: JOB_DISPLAY_URL -> Value http://jenkins-server:8080/job/wip/display/redirect
Name: JOB_NAME -> Value wip
Name: JOB_URL -> Value http://jenkins-server:8080/job/wip/
Name: RUN_ARTIFACTS_DISPLAY_URL -> Value http://jenkins-server:8080/job/wip/106/display/redirect?page=artifacts
Name: RUN_CHANGES_DISPLAY_URL -> Value http://jenkins-server:8080/job/wip/106/display/redirect?page=changes
Name: RUN_DISPLAY_URL -> Value http://jenkins-server:8080/job/wip/106/display/redirect
Name: RUN_TESTS_DISPLAY_URL -> Value http://jenkins-server:8080/job/wip/106/display/redirect?page=tests
I first noticed there is no WORKSPACE
, in the above list but there is a env.WORKSPACE
.
I then noticed there's a handful of key/value pairs that are either direct members of env
or members of the Map env.getEnvironment()
.
E.g. env.BUILD_ID
and env.getEnvironment()['BUILD_ID']
both exist...
whereas env.WORKSPACE
exists while env.getEnvironment()['WORKSPACE']
does not...
and env.CLASSPATH
does not exist whereas `env.getEnvironment()['CLASSPATH'] exists.
What is the logical distinction between the "direct" member objects of env
(e.g. env.BUILD_ID
) and the members of env.getEnvironment()
?
Between "env" and "getEnvironnment", and the fact that they're different, the notion of "environment" in the context of Jenkins feels muddled -- perhaps if someone can explain why they're distinct, it'll make sense to me when and why I should get information from env
vs. env.getEnvironment()
.
I didn't see env.getEnvironment()
or its distinction from env
's direct members documented at https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables or {{my_jenkins_url}}/job/{{job}}/pipeline-syntax/globals