For example:
var output=sh "echo foo";
echo "output=$output";
I will get:
output=0
So, apparently I get the exit code rather than the stdout. Is it possible to capture the stdout into a pipeline variable, such that I could get:
output=foo
as my result?
Try this:
Tested on:
Now, the
sh
step supports returning stdout by supplying the parameterreturnStdout
.See this example.
Note: The linked Jenkins issue has since been solved.
As mention in JENKINS-26133 it was not possible to get shell output as a variable. As a workaround suggested using of writ-read from temporary file. So, your example would have looked like:
You can try to use as well this functions to capture StdErr StdOut and return code.
Notice:
A short version would be: