title: Groovy parameter to shell script
body: <p>I've been trying to separate my code into two different files: <code>callTheFunction.groovy</code> and <code>theFunction.groovy</code>.</p>
  <p>As you can see from the name of the file:</p>
  <ul>
  <li><code>callTheFunction.groovy</code> calls the function defined in <code>theFunction.groovy</code>, passing random values in as parameters.</li>
  <li><code>theFunction</code> is a shell script - inside groovy function - which is supposed to use the parameters passed from <code>callTheFunction</code>.</li>
  </ul>
  <p><strong>PROBLEM:</strong><br />
  The shell script does not recognize/understand the arguments, the variables are empty, no value.</p>
  <p><strong>theFunction.groovy</strong></p>
  <pre class="lang-sh prettyprint-override"><code>def call(var1, var2) {
    sh '''
      echo &quot;MY values $var1 and $var2&quot;
    '''
  }
  </code></pre>
  <p><strong>callTheFunction.groovy</strong></p>
  <pre><code>def call {
    pipeline {
      stages {
        stage ('myscript') {
          steps {
            theFunction(&quot;Value1&quot;, &quot;Value2&quot;)
          }
        }
      }
    }
  }
  
  </code></pre>
  <p><strong>OUTPUT FROM PIPELINE:</strong></p>
  <pre><code>MY values  and
  </code></pre>
  <p>I am aware that there are similar issues out there:</p>
  <ul>
  <li><a href="https://stackoverflow.com/questions/41553303/pass-groovy-variable-to-shell-script">Pass groovy variable to shell script</a></li>
  <li><a href="https://www.edureka.co/community/56903/how-to-assign-a-groovy-variable-to-a-shell-variable" rel="nofollow noreferrer">How to assign groovy variable to shell variable</a></li>
  </ul>