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 usereturnStdout
andreturnStatus
parameters.Workarounds
Unfortunately this feature is still unsupported and missing. For more information please refer to official ticket:
Yes as luka5z mentioned, version 2.4 of Pipeline Nodes and Processes Plugin now supports this kind of stuff:
Seems if you try to return both in the same script, returnStatus will overwrite returnStdout which is a bit unfortunate.
You can read more in the official documentation here
Edit: Furthermore, it allows you finer grained control over failed/unstable build statuses too. You can see an example in my comment here