jenkins Pipeline脚本:如何从shell脚本获取返回值

我有一个詹金斯管道,我在不同阶段执行不同的脚本。但是,在一个阶段中,我想将阶段的输出传递到一个变量,在该变量中,我希望将该变量作为下一个阶段的输入进行传递。这是我在Jenkinsfile中的代码

timestamps
{
  node('cf_slave')
  {
    checkout scm
    stage('Download HA image from GSA')
    {
      withCredentials(usernamePassword(credentialsId: 'ssc4icp_GSA',usernameVariable: 'GSA_username',passwordVariable: 'GSA_PASSWORD')
      {
        environment {
          script {
            OUTPUT = """${sh(
                            returnStdout: true,script: 'bash jenkins/try_install.sh $VAR_ABC'
                         )}"""
            echo $OUTPUT
          }   
        }
      }       
    }
}
}

我在这里遇到语法错误。我想在OUTPUT变量中获取OUTPUT并将其传递到下一阶段。请帮助我以正确的方式完成操作

youbaio 回答:jenkins Pipeline脚本:如何从shell脚本获取返回值

在字符串之外引用变量时,不应使用美元符号($)。代码应为(包括Matt建议的更改):

timestamps
{
  node('cf_slave')
  {
    checkout scm
    stage('Download HA image from GSA')
    {
      withCredentials(usernamePassword(credentialsId: 'ssc4icp_GSA',usernameVariable: 'GSA_USERNAME',passwordVariable: 'GSA_PASSWORD'))
      {
        environment {
          script {
            OUTPUT = sh returnStdout: true,script: "bash jenkins/try_install.sh $VAR_ABC"
            echo OUTPUT
          }   
        }
      }
    }
  }
}
本文链接:https://www.f2er.com/3136034.html

大家都在问