title: Unable to run shell command in Groovy in Jenkins
body: <p>I am trying to get certain values from the slave by running shell commands such as :</p>
  
  <pre><code>git rev-parse HEAD
  git config --get remote.origin.url
  </code></pre>
  
  <p>The method that I have tried to write for this is :</p>
  
  <pre><code>def executeCommand(String command) {
      stdout = sh script: command, returnStdout: true
      return stdout.trim()
  }
  </code></pre>
  
  <p>Now when I try to run the first command :</p>
  
  <pre><code>output = executeCommand('git rev-parse HEAD')
  </code></pre>
  
  <p>I get the ERROR :</p>
  
  <pre><code>[Running] groovy "/Users/user-a/Documents/cmd.groovy"
  Caught: groovy.lang.MissingMethodException: No signature of method: cmd.sh() is applicable for argument types: (LinkedHashMap) values: [[script:git rev-parse HEAD, returnStdout:true]]
  Possible solutions: is(java.lang.Object), use([Ljava.lang.Object;), run(), run(), any(), tap(groovy.lang.Closure)
  groovy.lang.MissingMethodException: No signature of method: cmd.sh() is applicable for argument types: (LinkedHashMap) values: [[script:git rev-parse HEAD, returnStdout:true]]
  Possible solutions: is(java.lang.Object), use([Ljava.lang.Object;), run(), run(), any(), tap(groovy.lang.Closure)
      at cmd.executeCommand(cmd.groovy:2)
      at cmd.run(cmd.groovy:6)
  </code></pre>
  
  <p>I also tried:</p>
  
  <pre><code>output = command.execute().text
  </code></pre>
  
  <p>But this returns nothing.</p>
  
  <p>Im running out of ideas on how to run shell commands in Groovy in Jenkins and record the output.</p>
  
  <p><strong>MORE DETAILS</strong></p>
  
  <p>I am working with Jenkins shared Libraries. I have exposed a method in for my <code>Jenkinsfile</code> by the name <code>getLatestBuildDetails()</code>. This method is defined within my library. One of the actions within the method is to execute the <code>git</code> commands locally. So inorder to run any shell command locally, I have created the <code>executeCommand</code> function which takes the actual command to run as a String and executes it and returns the output to be used later by <code>getLatestBuildDetails()</code></p>