title: Run groovy script from bash script
body: <p>I want to run a Groovy script from within bash script. </p>
  
  <p>I have a groovy script that is creating a variable I need from jenkins. (The whole CI is written in bash for some reason). </p>
  
  <p>I need to run it in groovy because I can't reproduce it in bash. </p>
  
  <p>So my bash code looks like: </p>
  
  <pre><code>LAST_SUCCESSFUL_BUILD_DATE=$(groovy scripts/jenkins-lastbuild-date.groovy)
  </code></pre>
  
  <p>The groovy script is in the folder scripts, and it's like this: </p>
  
  <pre><code>#!/usr/bin/env groovy
  import jenkins.model.Jenkins
  
  def envVars = Jenkins.instance.getGlobalNodeProperties()[0].getEnvVars()
  
  // the job name is a global Jenkins variable, so I get it from there
  def item = Jenkins.instance.getItem(envVars['JOB_NAME'])
  
  def  ff=item.getLastSuccessfulBuild()
  println ff.getTime().format("yyyy-MM-dd")
  </code></pre>
  
  <p>but when I run it I get the error </p>
  
  <pre><code>line 254: groovy: command not found
  </code></pre>
  
  <p>any ideas? I need to get the date from the last successful commit. </p>