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.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.