title: How can I call function from another file in Jenkins pipeline?
body: <p>I want to collect functions common for pipelines in a separate file. I created directories' structure:</p>
  <pre><code>vars/
  ...commonFunctions.groovy
  pipeline.jenkinsfile
  anotherPipeline.jenkinsfile
  </code></pre>
  <p>commonFunctions.groovy:</p>
  <pre><code>def buildDocker(def par, def par2) {
    println(&quot;build docker...&quot;)
  }
  
  return this;
  </code></pre>
  <p>In pipeline.jenkinsfile I want to call buildDocker function. How can I do this? I tried simply <code>commonFunctions.buildDocker(par1, par2)</code> in the pipelines, but get MethodNotFound error.</p>
  <p>UPD:</p>
  <p>relevant part of pipeline.jenkinsfile:</p>
  <pre><code>    stage('Checkout') {
          steps {
              checkout([$class           : 'GitSCM',
                        branches         : [[name: gitCommit]],
                        userRemoteConfigs: [[credentialsId: gitCredId, url: gitUrl]]
              ])
          }
      }
  
      stage(&quot;Build Docker&quot;) {
          steps {
              catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
                  script {
                      // here want to call function from another file
                      commonFunctions.buildDocker(par1, par2)
                  }
              }
          }
      }
  </code></pre>