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
?
Best Answer
The latest version of the pipeline
sh
step allows you to do the following;Another feature is the
returnStatus
option.These options where added based on this issue.
See official documentation for the
sh
command.For declarative pipelines (see comments), you need to wrap code into
script
step: