26

I would like to print all available properties (and their values) in env object inside Jenkinsfile.

When I do

print env

I get:

org.jenkinsci.plugins.workflow.cps.EnvActionImpl@112cebc2

So it looks like toString is not implemented there, how can I access properties that are in this object if I don't know their names?

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115

3 Answers3

21

Make sure you're not running the pipeline script in sandboxed mode and you should be able to use:

env.getEnvironment()

Note, if you're running in sandbox mode in a pipeline, you should approve the method at the script approval page: http://jenkins-host/scriptApproval/

Alex
  • 8,093
  • 6
  • 49
  • 79
TomDotTom
  • 6,238
  • 3
  • 41
  • 39
7

To retrieve all env properties using a Jenkinsfile written in either declarative or scripted DSL you can use:

sh 'env'                       

or

sh 'printenv'
Zach Weg
  • 1,553
  • 11
  • 13
4

As said over here: https://stackoverflow.com/a/42138466/618253

The declarative pipeline way of doing things:

node {
   echo sh(returnStdout: true, script: 'env')
}
july
  • 332
  • 1
  • 6