检索Jenkinsfile中env的所有属性

Krz*_*soń 15 groovy jenkins-workflow jenkinsfile

我想env在Jenkinsfile 中的对象中打印所有可用的属性(及其值).

当我做

print env
Run Code Online (Sandbox Code Playgroud)

我明白了:

org.jenkinsci.plugins.workflow.cps.EnvActionImpl@112cebc2
Run Code Online (Sandbox Code Playgroud)

所以看起来好像toString没有在那里实现,如果我不知道他们的名字怎么能访问这个对象中的属性?

Tom*_*Tom 15

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

env.getEnvironment()
Run Code Online (Sandbox Code Playgroud)

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


Zac*_*Weg 6

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

sh 'env'                       
Run Code Online (Sandbox Code Playgroud)

或者

sh 'printenv'
Run Code Online (Sandbox Code Playgroud)