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


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



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.


Have more questions?


  • 1
    Parichay Barpanda

    Is there a way to send a POST request to Jenkins so that user can create an env variable?

  • 0
    Lokesh Kamalay

    I don't think there is one... you may consider JCasC (jenkins configuration as code)

Please sign in to leave a comment.