例如:
var output=sh "echo foo";
echo "output=$output";
我会得到:
output=0
所以,显然我得到的是退出代码而不是标准输出。是否可以将标准输出捕获到管道变量中,以便我可以获得:output=foo
作为我的结果?
Now https://issues.jenkins-ci.org/browse/JENKINS-26133, the sh step https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#sh-shell-script支持退货stdout通过提供参数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)
See 这个例子 https://github.com/jenkinsci/pipeline-examples/blob/master/pipeline-examples/gitcommit/gitcommit.groovy.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)