简体   繁体   English

如何通过Jenkins Pipeline插件中的groovy脚本访问全局环境

[英]How to access global environment through groovy script in Jenkins Pipeline Plugin

In shell we use following command 在shell中,我们使用以下命令

  node{
     sh "x=${env.j_properties_file}"
     sh "y=${env.HOME}"
  }

How do we it in groovy script Or How do we access shell variable x in groovy script? 我们如何在groovy脚本中使用它或如何在groovy脚本中访问外壳变量x?

you can't access them directly, but according to the reference you can catch stdout from your sh step: 您不能直接访问它们,但是根据参考,您可以从sh步骤中捕获stdout:

node{
    def xx = sh(returnStdout:true, script:"""
        x=${env.j_properties_file}
        echo \${x}
    """)

    echo "the shell output = ${xx}"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM