title: Jenkins Groovy script to execute shell commands
body: <p>I'm using a groovy script to calculate my build duration and publish a metric to Hosted Graphite, from the command line the following curl will result with the intend effect:</p>
  
  <pre><code>echo {someMetricHere} | nc carbon.hostedgraphite.com 2003
  </code></pre>
  
  <p>However in my groovy script the last step having generated a metric is to run the following:</p>
  
  <pre><code>"echo "+ metric +" | nc carbon.hostedgraphite.com 2003".execute()
  </code></pre>
  
  <p>Its returning:</p>
  
  <p>Caught: java.io.IOException: Cannot run program "|": error=20, Not a directory
  java.io.IOException: Cannot run program "|": error=20, Not a directory
      at hudson8814765985646265134.run(hudson8814765985646265134.groovy:27)
  Caused by: java.io.IOException: error=20, Not a directory
      ... 1 more</p>
  
  <p>I assume the command doesn't understand the "|" part of the command, any suggestions how I can fix this script to run the intended bash? I thought it might be possible to create a .sh file in the workspace but am not sure how.</p>
  
  <p>Pastebin for those wanting to see full script: <a href="https://pastebin.com/izaXVucF" rel="nofollow noreferrer">https://pastebin.com/izaXVucF</a></p>
  
  <p>Cheers :)</p>