title: How to call a groovy function from a Jenkinsfile?
body: <p>Despite following <a href="https://stackoverflow.com/questions/37800195/how-do-you-load-a-groovy-file-and-execute-it">this answer</a> and others, I am unable to successfully use a local groovy file in my Jenkinsfile (both are in the same repository).</p>
  
  <pre><code>def deployer = null
  ...
  ...
  ...
  pipeline {
     agent {
        label 'cf_slave'
     }
  
     options {
        skipDefaultCheckout()
        disableConcurrentBuilds()
     }
  
     stages {
        stage ("Checkout SCM") {
           steps {
              checkout scm
           }
        }
        ...
        ...
        ...
        stage ("Publish CF app") {
            steps {
                script {
                    STAGE_NAME = "Publish CF app"
                    deployer = fileLoader.load ('deployer')
  
                    withCredentials(...) {   
                        if (BRANCH_NAME == "develop") {
                            ...
                            ...
                            ...
                        } else {
                            deployer.generateManifest()
                        }
                    }
                }
            }
        }
        ...
        ...
    }
  </code></pre>
  
  <p><strong>deployer.groovy</strong>:</p>
  
  <pre><code>#!/usr/bin/env groovy
  
  def generateManifest() {
     sh "..."
     echo "..."
  }
  </code></pre>
  
  <p>In the console log (<a href="http://pastebin.com/j7dWrFQq" rel="noreferrer">stack</a>): </p>
  
  <pre><code>[Pipeline] stage
  [Pipeline] { (Publish CF app)
  [Pipeline] script
  [Pipeline] {
  [Pipeline] echo
  before loading groovy file
  [Pipeline] echo
  Loading from deployer.groovy
  [Pipeline] load
  [Pipeline] // load
  [Pipeline] }
  [Pipeline] // script
  [Pipeline] }
  [Pipeline] // stage
  </code></pre>
  
  <hr>
  
  <p><strong>Update:</strong></p>
  
  <p>It seems the problem was not with loading the file but rather with the contents of the file, where I execute the following which apparently does not play well:</p>
  
  <pre><code>sh "node $(pwd)/config/mustacher manifest.template.yml config/environments/common.json config/environments/someFile.json"
  echo "..."
  </code></pre>
  
  <p>When only the <code>echo</code> is there, <a href="http://pastebin.com/G5MXc7YF" rel="noreferrer">this is the stack</a>.</p>
  
  <p>So not the <code>sh "node ..."</code> nor the <code>echo</code> work. Even changing it just to <code>sh "pwd"</code> fails as well. What could it be? the syntax in the file? the way it is called in the pipeline?</p>
  
  <p>If I will make the same node call in the pipeline (for example in the <code>withCredentials</code> <code>if</code> statement, it works.</p>