title: Jenkins pipeline sh returnstdout not working
body: <p>I am attempting to use the returnStdout feature of the Jenkins pipeline sh command. defined here <a href="https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script" rel="noreferrer">https://jenkins.io/doc/pipeline/steps/workflow-durable-task-step/#code-sh-code-shell-script</a></p>
  
  <p>Pulling from previous question and answers: <a href="https://stackoverflow.com/questions/36507410/is-it-possible-to-capture-the-stdout-from-the-sh-dsl-command-in-the-pipeline">Is it possible to capture the stdout from the sh DSL command in the pipeline</a></p>
  
  <p>My original code:</p>
  
  <pre><code>node{
  def output = sh(returnStdout: true, script: 'pwd')
  println "output = ${output}"
  }
  </code></pre>
  
  <p>and its result. You can see that I am getting exit code instead of the result passed into my variable:</p>
  
  <pre><code>[Pipeline] node {
  [Pipeline] sh
  [Update_Stageing_DB] Running shell script
  + pwd
  /mnt/storage/jenkins/workspace/Update_Stageing_DB
  [Pipeline] echo
  output = 0
  [Pipeline] } //node
  [Pipeline] Allocate node : End
  [Pipeline] End of Pipeline
  Finished: SUCCESS
  </code></pre>
  
  <p>Based on the examples I figured I might need to add the .trim() so my updated code looks like this:</p>
  
  <pre><code>node{
  def output = sh(returnStdout: true, script: 'pwd').trim()
  println "output = ${output}"
  }
  </code></pre>
  
  <p>But this results in the entire job to fail:</p>
  
  <pre><code>[Pipeline] node {
  [Pipeline] sh
  [Update_Stageing_DB] Running shell script
  + pwd
  /mnt/storage/jenkins/workspace/Update_Stageing_DB
  [Pipeline] } //node
  [Pipeline] Allocate node : End
  [Pipeline] End of Pipeline
  hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.trim() is applicable for argument types: () values: []
  Possible solutions: wait(), grep(), wait(long), times(groovy.lang.Closure), div(java.lang.Character), print(java.io.PrintWriter)
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
  at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:49)
  at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
  at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:15)
  at WorkflowScript.run(WorkflowScript:3)
  at ___cps.transform___(Native Method)
  at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:55)
  at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:106)
  at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:74)
  at sun.reflect.GeneratedMethodAccessor771.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:606)
  at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
  at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
  at com.cloudbees.groovy.cps.Next.step(Next.java:58)
  at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:154)
  at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:164)
  at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:277)
  at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
  at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
  at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
  at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
  at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
  at java.util.concurrent.FutureTask.run(FutureTask.java:262)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
  at java.lang.Thread.run(Thread.java:745)
  Finished: FAILURE
  </code></pre>
  
  <p>Im sure i'm missing something basic but for the life of me I cant see whats wrong with this simple code. Any help would be appreciated.</p>
  
  <p>Jenkins ver. 2.32.2</p>