How to use @Library in an imported groovy script in Jenkins declarative pipeline?

前端 未结 1 622
一向
一向 2021-01-04 21:21

What I have is a following:

  1. global shared library created as described here. Nothing special, one script in vars folder called deleteFile.gr
相关标签:
1条回答
  • 2021-01-04 21:58

    For this use case, it will make more sense to use the library step to dynamically load it at runtime.

    In your firstPipe.groovy you could do something like:

    final myOneLib = 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
        myOneLib.deleteFile 'for 3rd party global library now'
      }
    }
    
    return this
    

    See the Loading libraries dynamically section of the Extending with Shared Libraries documentation.

    0 讨论(0)
提交回复
热议问题