Pipeline - How to print out env variables available in a build

Article ID:230610987
1 minute readKnowledge base

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)?

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.