Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve all properties of env in Jenkinsfile

Tags:

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?

like image 300
Krzysztof Krasoń Avatar asked Apr 25 '16 09:04

Krzysztof Krasoń


People also ask

How do I get environment variables in Groovy Jenkins?

In "Manage Jenkins" -> "Configure System" -> "Global Properties" -> "Environment Variables" I added "ALL_NODES_ENVVAR".


2 Answers

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/

like image 196
TomDotTom Avatar answered Sep 27 '22 19:09

TomDotTom


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

sh 'env'                        

or

sh 'printenv' 
like image 24
Zach Weg Avatar answered Sep 27 '22 19:09

Zach Weg