title: How to use @Library in an imported groovy script in Jenkins declarative pipeline?
body: <p>What I have is a following:</p>
  
  <ol>
  <li>global shared library created as described <a href="https://jenkins.io/doc/book/pipeline/shared-libraries/" rel="noreferrer">here</a>. Nothing special, one script in <code>vars</code> folder called <code>deleteFile.groovy</code>, tried it - works. Library is called <code>myOneLib</code></li>
  <li>a pipeline script called <code>firstPipe.groovy</code></li>
  </ol>
  
  <pre><code>@Library('myOneLib') _
  
  def execute(String zCmakeListsPath){
      stage('some kind of stage 2') {
          echo "Hello from stage 1 with " + zCmakeListsPath
          echo "var attempt ${env.mySrcDir}"
  
      }
      stage('second stage'){
              echo "and one from stage 2"
              echo "param was " + zCmakeListsPath
              echo "var attempt ${env.myBuildDir}"
              //call function from global lib
              deleteFile 'for 3rd party global library now'
      }
  }
  
  return this</code></pre>
  
  <ol start="3">
  <li>a pipeline script called <code>caller.groovy</code> that is calling <code>firstPipe.groovy</code></li>
  </ol>
  
  <pre><code>pipeline {
      agent any
       environment {
              myBuildDir = "thisShoulbBeBuild"
              mySrcDir = "andHereIsSrc"
          }
      stages {
          stage('first') {
              steps {
                  script{
                      echo 'beggining with ' + myBuildDir
                      def rootDir = pwd()
                      echo 'rootDir is ' + rootDir
                      def example = load "${rootDir}/fullPipe/firstPipe.groovy"
                      example.execute("rasAlGhul")
                  }
              }
          }
      }
  }</code></pre>
  
  <p>Now, when I run the build like this, I get the following error:</p>
  
  <blockquote>
    <p>ERROR: Could not find any definition of libraries [myOneLib]</p>
  </blockquote>
  
  <p>but when I simply move the line <code>@Library('myOneLib') _</code> to the top of <code>caller.groovy</code> everything works.</p>
  
  <p>So my question is how do use the <code>@Library</code> in the imported/included script? Or is there some other way to specify the global library?</p>
  
  <p>Few more notes: <code>caller.groovy</code> and <code>firstPipe.groovy</code> are in the same git repo, and if I eliminate usage of the global library, everything works fine. I'm using declarative pipeline and would like to continue to do so.</p>