title: Can't store sh command output through DSL (groovy) in Jenkins pipeline job
body: <p>I would like to get last build output in pipeline Jenkins job and attach in email (using emailext plugin). Curl works fine and gives proper build output but i can't store in variable to attach in the email. I'm using latest jenkins version.</p>
  
  <p>I can see there are couple of related posts for simple sh command but that doesn't work for curl response store.</p>
  
  <h1>Tried code:</h1>
  
  <p>1.</p>
  
  <pre><code>def consoleOutput = sh(returnStdout: true, script: 'curl http://' + jenkinsUser + ':' + jenkinsUserToken + '@' + jenkinsServer + ':8080/job/' + 'myJob/lastBuild/consoleText').trim()
  echo consoleOutput
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>sh 'curl http://' + jenkinsUser + ':' + jenkinsUserToken + '@' + jenkinsServer + ':8080/job/' + "${env.JOB_NAME}" + '/lastBuild/consoleText; echo $? &gt; status'
  def consoleOutput = readFile('status').trim()
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>def consoleOutput = sh(script: 'curl http://' + jenkinsUser + ':' + jenkinsUserToken + '@' + jenkinsServer + ':8080/job/' + '/myJob/lastBuild/consoleText', returnStatus: true).split("\r?\n")
  echo consoleOutput
  </code></pre>