title: How can I reference the Jenkinsfile directory, with Pipeline?
body: <p>I have a groovy file, I want to run from the Jenkinsfile.</p>
  
  <p>ie. <code>load script.groovy</code></p>
  
  <p>However, I am not sure how I can reference this file if it is stored in the same directory as the Jenkinsfile. I am loading the Jenkinsfile from git. I noticed it creates a folder called <code>workspace@script</code>. It does not place this in the workspace directory. I could hardcode the folder but I am not sure the rules on this and it seems a little redundant to check-out the code again. </p>
  
  <pre><code>java.io.FileNotFoundException: /opt/jenkins_home/jobs/my_job/workspace/script.groovy (No such file or directory)
  </code></pre>
  
  <p>By default it loads from workspace, instead of <code>workspace@script</code></p>
  
  <p>I am trying to convert a a BuildFlow script to a Pipeline (Workflow) script. But I am finding, it is not as easy as a copy and paste. </p>
  
  <p>Jenkinsfile</p>
  
  <pre><code>node {
  
  //get parameters from Job
  def builds = builds.tokenize(",")
  def ip_address_node = ip_address_node.trim()
  def port_node = port_node.trim()
  def branch = branch.trim()
  def workspace = pwd()
  
  stage 'Checking out code from esb repository'
  git branch: branch, url: 'ssh://git@giturl/integration_bus.git'
  
  load '../workspace@script/esb_deploybar_pipeline/deploy_esb.groovy'
  
  }
  </code></pre>
  
  <p>deploy_esb.groovy (this is from old buildflow, trying to run in a pipeline)</p>
  
  <pre><code>import groovy.transform.ToString
  import groovy.transform.EqualsAndHashCode
  @EqualsAndHashCode
  @ToString
  class BarDeploy {
      String barFile
      String app
      String integrationServer
  }
  
  
  //parse csv
  def csvItemsApps = new HashSet&lt;BarDeploy&gt;();
  def csvItemsLibs = new HashSet&lt;BarDeploy&gt;();
  def deploymentMapFile = new File(workspace + "/ESB_Deployment_Map.csv")
  def isFirstLine = true
  
  stage 'Parsing ESB Deployment CSV'
  deploymentMapFile.withReader { reader -&gt;
      while(line = reader.readLine()) {
          if(isFirstLine)
          {
            isFirstLine = false
            continue
          }
  
          csvLine = line.split(",")
          app = csvLine[0]
          intServer = csvLine[1]
  
          def barDeploy = new BarDeploy()
          barDeploy.app = app
          barDeploy.integrationServer = intServer
          csvItemsApps.add(barDeploy)
  
  
          //get shared libs
          if(csvLine.length &gt; 2 &amp;&amp; csvLine[2] != null)
          {
              def sharedLibs = csvLine[2].split(";")
              sharedLibs.each { libString -&gt;
                  if(!libString.isAllWhitespace())
                  {
                      def lib = new BarDeploy()
                      lib.app = libString
                      lib.integrationServer = intServer
                      csvItemsLibs.add(lib)
                  }
              };
          }
      }
  };
  
  //get list of bar files to deploy from html and consolidate bar files to deploy with apps in csv 
  for (int i = 0; i &lt; builds.size(); i+=3)
  {
      if(builds[i].equals("false"))
      {
          //Don't deploy bar if checkbox isn't selected
          continue
      }
  
      foundInCSV = false
  
      appToDeploy = builds[i + 1]
      barFileToDeploy = builds[i + 2]
  
      iterator = csvItemsApps.iterator()
      while (iterator.hasNext())
      {
          barDeploy = iterator.next()
          if(appToDeploy.equalsIgnoreCase(barDeploy.app))
          {
              barDeploy.barFile = barFileToDeploy
              foundInCSV = true
          }
      }
  
      iterator = csvItemsLibs.iterator()
      while (iterator.hasNext())
      {
          barDeploy = iterator.next()
          if(appToDeploy.equalsIgnoreCase(barDeploy.app))
          {
              barDeploy.barFile = barFileToDeploy
              foundInCSV = true
          }
      }
  
      if(foundInCSV == false)
      {
          throw new RuntimeException("App: " + appToDeploy + " not found in ESB_Deployment_Map.csv. Please add CSV Entry.")
      }
  }
  
  
  //Do deploy, deploy shared libs first
  deployCSVItemsInParallel(ip_address_node,port_node,branch,env_key,csvItemsLibs)
  deployCSVItemsInParallel(ip_address_node,port_node,branch,env_key,csvItemsApps)
  
  
  def deploy(ip_address_node,port_node,branch,deployItem,env_key)
  {
      def integrationServer = deployItem.integrationServer
      def app = deployItem.app
      def barFile = deployItem.barFile
  
      if(barFile == null)
      {
          return;
      }
  
      println("Triggering Build -&gt; ESB App = " + app +  ", Branch = " 
              + branch + ", Barfile: " + barFile + ", Integration Server = " + integrationServer + ", IP Address: " + ip_address_node 
              + ", Port: " + port_node + ", Env_Key: " + env_key)
  
      build_closure = { -&gt;
          build("esb_deploybar", 
                        ip_address_node: ip_address_node, port_node: port_node,
                        integrationServer: integrationServer, branch: branch, app: app, barFile: barFile, env_key: env_key)
      }
  
      return build_closure
  }
  
  def deployCSVItemsInParallel(ip_address_node,port_node,branch,env_key,csvItems)
  {
      def build_closures = []
      iterator = csvItems.iterator()
      while (iterator.hasNext())
      {
        barDeploy = iterator.next()
        def build_closure = deploy(ip_address_node,port_node,branch,barDeploy,env_key)
  
        if(build_closure != null)
        {
            build_closures.add(build_closure)
        }
      }
  
      if(build_closures?.size() &gt; 0)
      {
           parallel(build_closures)
      }
  }
  </code></pre>