例如:
var output=sh "echo foo"; echo "output=$output";
我会得到:
output=0
因此,显然我得到的是退出代码,而不是标准输出。是否有可能将stdout捕获到管道变量中,这样我就可以得到: output=foo 作为结果?
output=foo
现在,该sh步骤通过提供参数来支持返回 stdoutreturnStdout。
sh
returnStdout
// 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)
请参阅此示例。