【问题标题】:How to access global environment through groovy script in Jenkins Pipeline Plugin如何通过 Jenkins Pipeline Plugin 中的 groovy 脚本访问全局环境
【发布时间】:2017-11-23 03:56:46
【问题描述】:

在shell中我们使用以下命令

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

我们如何在 groovy 脚本中使用它或者我们如何在 groovy 脚本中访问 shell 变量 x?

【问题讨论】:

标签: bash jenkins groovy jenkins-pipeline


【解决方案1】:

您不能直接访问它们,但根据reference 您可以从sh 步骤中捕获标准输出:

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

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

【讨论】:

    猜你喜欢
    • 2018-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 2020-12-26
    • 2019-10-22
    相关资源
    最近更新 更多