Issue
-
How can I print all of the current environment variables in a Pipeline build?
-
How can I print the environment variables of a downstream build (Pipeline or not)?
Environment
-
CloudBees CI (CloudBees Core) on modern cloud platforms - Managed controller
-
CloudBees CI (CloudBees Core) on traditional platforms - Client controller
-
CloudBees Jenkins Enterprise - Managed controller
Resolution
Printing the variables of the current build
For linux env
You can use the printenv
command:
sh 'printenv'
For windows env
You can use the set
command:
bat 'set'
Special case: printing the build variables of a downstream build
You can print the build variables used by a downstream job triggered with the build
directive:
def run = build 'quality-freestyle' echo "${run.buildVariables}"
Please that prior to the [Pipeline Supporting APIs Plugin] version 2.15 this was not working if the downstream job was not a Pipeline job.