title: how to "include" another file as part of a Jenkins Pipeline definition
body: <p>We have a large project that has multiple separate declarative pipeline file definitions.  This is used to build different apps and installers from the single code base.</p>
  
  <p>Right now, all of these files contain a large block of "code" used to generate the email body and JIRA update messages.  examples:</p>
  
  <pre><code>// Get a JIRA's to add Comments to
  // Return map of JIRA id to comment text from all commits for that JIRA
  @NonCPS
  def getJiraMap() {
    a bunch of stuff
  return jiraset
  }
  
  // Get the body text for the emails
  def getMailBody1() {
      return "See: ${BUILD_URL}\n\nChanges:\n" + getChangeString() + "\n" + testStatuses()
  }
  
  etc...
  </code></pre>
  
  <p>What I would like to do is have all these common methods in a separate file that all the other pipeline files can include.  This seems like it SHOULD be easy, but all examples I've found appear to be rather complex involving a separate SCM - which is NOT what I want.</p>
  
  <p>Updates:</p>
  
  <p>Going through the various suggestions given in that link, I make the following file - BuildTools.groovy:  Note that this file is in the same directory as the jenkins pipeline file that uses it.</p>
  
  <pre><code>import hudson.tasks.test.AbstractTestResultAction
  import hudson.model.Actionable
  
  Class BuildTools {
  
  // Get a JIRA's to add Comments to
  // Return map of JIRA id to comment text from all commits for that JIRA
  @NonCPS
  def getJiraMap() {
      def jiraset = [:]
  .. whole bunch of stuff ..
  </code></pre>
  
  <p>Here are the various things I've tried, and the results.</p>
  
  <pre><code>File sourceFile = new File("./AutomatedBuild/BuildTools.groovy");
  Class gcl = new GroovyClassLoader(getClass().getClassLoader()).parseClass(sourceFile);
  GroovyObject bt = (GroovyObject) gcl.newInstance();
  
  Fails with:
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use method java.lang.Class getClassLoader
  </code></pre>
  
  <pre><code>evaluate(new File("./AutomatedBuild/BuildTools.groovy"))
  def bt = new BuildTools()
  
  Fails with:
      15:29:07  WorkflowScript: 8: unable to resolve class BuildTools 
      15:29:07   @ line 8, column 10.
      15:29:07     def bt = new BuildTools()
      15:29:07              ^
  </code></pre>
  
  <pre><code>import BuildTools
  def bt = new BuildTools()
  
  Fails with:
      15:35:58  WorkflowScript: 16: unable to resolve class BuildTools (note that BuildTools.groovy is in the same folder as this script)
      15:35:58   @ line 16, column 1.
      15:35:58     import BuildTools
      15:35:58     ^
  </code></pre>
  
  <pre><code>GroovyShell shell = new GroovyShell()
  def bt = shell.parse(new File("./AutomatedBuild/BuildTools.groovy"))
  
  Fails with:
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: Scripts not permitted to use new groovy.lang.GroovyShell
  </code></pre>