小编典典

是否可以从管道中的sh DSL命令捕获stdout

jenkins

例如:

var output=sh "echo foo";
echo "output=$output";

我会得到:

output=0

因此,显然我得到的是退出代码,而不是标准输出。是否有可能将stdout捕获到管道变量中,这样我就可以得到: output=foo 作为结果?


阅读 270

收藏
2020-07-25

共1个答案

小编典典

现在,该sh步骤通过提供参数来支持返回 stdoutreturnStdout

// These should all be performed at the point where you've
// checked out your sources on the slave. A 'git' executable
// must be available.
// Most typical, if you're not cloning into a sub directory
gitCommit = sh(returnStdout: true, script: 'git rev-parse HEAD').trim()
// short SHA, possibly better for chat notifications, etc.
shortCommit = gitCommit.take(6)

请参阅此示例

2020-07-25