问题描述
有没有更好的方法在Jenkins 2.0管道中运行shell任务,然后返回命令的 code>和 returnStatus 参数。解决方法
不幸的是,这个功能仍然不被支持和丢失。欲了解更多信息,请参阅官方:
Is there a better way to run a shell task in a Jenkins 2.0 pipeline and then return the stdout of the command. The only way I can get this to work is to pipe the output of the command to a file and then read the file in to a variable.
sh('git config --get remote.origin.url > GIT_URL') def stdout = readFile('GIT_URL').trim()
This seems like a really bad way to return the output. I was hoping I could do something like:
def stdout = sh('git config --get remote.origin.url').stdout
or
def exitcode = sh('git config --get remote.origin.url').exitcode
Is this possible?
Update
Since 6/2016 JENKINS-26133 is officially marked as Resolved. Therefore, before trying below workarounds, first try supported implementation for sh/bat which makes it possible to use returnStdout and returnStatus parameters.
Workarounds
Unfortunately this feature is still unsupported and missing. For more information please refer to official ticket:
这篇关于如何在Jenkins 2.0 Pipeline作业中执行命令,然后返回stdout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!