例如:
var output=sh "echo foo";
echo "output=$output";
我会得到:
output=0
所以,显然我得到的是退出代码而不是标准输出。是否可以将标准输出捕获到管道变量中,以便我可以获得:
输出=foo
作为我的结果?
最佳答案
Now ,sh
step支持通过提供参数returnStdout
返回stdout。
// 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)
参见this example .
关于jenkins - 是否可以从管道中的 sh DSL 命令捕获标准输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36507410/