Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jenkins管道脚本:如何从shell脚本获取返回值_Jenkins_Jenkins Pipeline - Fatal编程技术网

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

jenkins管道脚本:如何从shell脚本获取返回值,jenkins,jenkins-pipeline,Jenkins,Jenkins Pipeline,我有一个jenkins管道,我在不同的阶段执行不同的脚本。但是,在一个阶段中,我希望将该阶段的输出传递给一个变量,在这个变量中,我希望将该变量作为输入传递给下一个阶段。这是我在Jenkins文件中的代码 timestamps { node('cf_slave') { checkout scm stage('Download HA image from GSA') { withCredentials(usernamePassword(credential

我有一个jenkins管道,我在不同的阶段执行不同的脚本。但是,在一个阶段中,我希望将该阶段的输出传递给一个变量,在这个变量中,我希望将该变量作为输入传递给下一个阶段。这是我在Jenkins文件中的代码

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
          }   
        }
      }       
    }
}
}

这里我得到了语法错误。我想在输出变量中获得输出,并将其传递到下一阶段。请帮助我如何以正确的方式执行此操作

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


sh
是一种管道方法,不能转换为字符串。尝试删除
“${…}”“”
,然后在
脚本的字符串输入中将单引号修改为双引号,它应该可以工作。我将代码更改为
OUTPUT=sh(returnStdout:true,脚本:“bash jenkins/Try\u install.sh$VAR\u ABC”)
但仍会收到错误消息
在耐久性级别运行:MAX_SURVIVABILITY org.codehaus.groovy.control.multiplecompiletonErrorsException:启动失败:WorkflowScript:44:意外标记:}@44行第5列。}^1错误
我收到与此代码相同的错误,我还发现了另一个错误在代码中,第8行缺少一个右括号(withCredentials…)。
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
          }   
        }
      }
    }
  }
}