How to list all `env` properties within jenkins pipeline job?
According to Jenkins documentation for declarative pipeline:
sh 'printenv'
For Jenkins scripted pipeline:
echo sh(script: 'env|sort', returnStdout: true)
The above also sorts your env vars for convenience.
Another, more concise way:
node { echo sh(returnStdout: true, script: 'env') // ...}
cf. https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script
The following works:
@NonCPSdef printParams() { env.getEnvironment().each { name, value -> println "Name: $name -> Value $value" }}printParams()
Note that it will most probably fail on first execution and require you approve various groovy methods to run in jenkins sandbox. This is done in "manage jenkins/in-process script approval"
The list I got included:
- BUILD_DISPLAY_NAME
- BUILD_ID
- BUILD_NUMBER
- BUILD_TAG
- BUILD_URL
- CLASSPATH
- HUDSON_HOME
- HUDSON_SERVER_COOKIE
- HUDSON_URL
- JENKINS_HOME
- JENKINS_SERVER_COOKIE
- JENKINS_URL
- JOB_BASE_NAME
- JOB_NAME
- JOB_URL