[JIRA] (JENKINS-44930) Allow sh to return exit status, stdout and stderr all at once
Title: Message Title Suraj Sharma edited a comment on JENKINS-44930 Re: Allow sh to return exit status, stdout and stderr all at once Maybe this small function can help take care of exit status and stdout.{code:java}def runCommand(script) {echo "[runCommand:script] ${script}"def stdoutFile = "rc.${BUILD_NUMBER}.out"script = script + " > " + stdoutFiledef res = [:]res["exitCode"] = sh(returnStatus: true, script: script)res["stdout"] = sh(returnStdout: true, script: "cat " + stdoutFile)sh(returnStatus: true, script: "rm -f " + stdoutFile)echo "[runCommand:response] ${res}"return res}{code} Example Usage{code}def response = runCommand("date")echo response["exitCode"]echo response["stdout"]{code} Add Comment This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.183003.149756330.14555.1559083922795%40Atlassian.JIRA. For more options, visit https://groups.google.com/d/optout.
[JIRA] (JENKINS-44930) Allow sh to return exit status, stdout and stderr all at once
Title: Message Title Suraj Sharma commented on JENKINS-44930 Re: Allow sh to return exit status, stdout and stderr all at once Maybe this small function can help take care of exit status and stdout. def runCommand(script) { echo "[runCommand:script] ${script}" def stdoutFile = "rc.${BUILD_NUMBER}.out" script = script + " > " + stdoutFile def res = [:] res["exitCode"] = sh(returnStatus: true, script: script) res["stdout"] = sh(returnStdout: true, script: "cat " + stdoutFile) sh(returnStatus: true, script: "rm -f " + stdoutFile) echo "[runCommand:response] ${res}" return res } Add Comment This message was sent by Atlassian Jira (v7.11.2#711002-sha1:fdc329d) -- You received this message because you are subscribed to the Google Groups "Jenkins Issues" group. To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-issues+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-issues/JIRA.183003.149756330.14405.1559083801450%40Atlassian.JIRA. For more options, visit https://groups.google.com/d/optout.