How do I get the output of a shell command executed using into a variable from Jenkinsfile (groovy)?

I have something like this on a Jenkinsfile (Groovy) and I want to record the stdout and the exit code in a variable in order to use the information later.

sh "ls -l"

How can I do this, especially as it seems that you cannot really run any kind of groovy code inside the Jenkinsfile?

10 Answers
10

Leave a Comment