Retrieve all properties of env in Jenkinsfile

时间:2016-04-25 09:35:45

标签: groovy jenkins-workflow jenkinsfile

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?

3 个答案:

答案 0 :(得分:14)

确保您没有以沙盒模式运行管道脚本,并且您应该可以使用:

env.getEnvironment()

注意,如果您在管道中以沙盒模式运行,则应在脚本审批页面上批准该方法:http://jenkins-host/scriptApproval/

答案 1 :(得分:1)

如上所述:https://stackoverflow.com/a/42138466/618253

声明性管道方式:

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

答案 2 :(得分:0)

要使用以声明或脚本化DSL编写的Jenkins文件检索所有env属性,您可以使用:

sh 'env'                       

sh 'printenv'