Retrieve all properties of env in Jenkinsfile

不羁的心 提交于 2019-11-28 03:00:36

问题


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?


回答1:


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/




回答2:


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

The declarative pipeline way of doing things:

node {
   echo sh(returnStdout: true, script: 'env')
}



回答3:


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

sh 'env'                       

or

sh 'printenv'


来源:https://stackoverflow.com/questions/36836806/retrieve-all-properties-of-env-in-jenkinsfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!