如何将bash变量传递到groovy中?

时间:2018-10-28 14:37:58

标签: jenkins-pipeline

我正在尝试编写一个jenkinsfile来通过管道运行作业。我要求将变量的值从shell传递到groovy。我的jenkinsfile用的语言很烂,但是我在某个地方使用了shell命令。

预先感谢

1 个答案:

答案 0 :(得分:0)

因此,执行此操作的“方法”而非“方法”可能是让Shell步骤将值写入文件:

sh 'echo "${NEEDED_VALUE} > needed.value.txt'

然后以常规方式获取该值:

script {
  def neededValue = readFile('needed.value.txt')
  // do something with the value here
}