How do you load a groovy file and execute it

后端 未结 5 637
梦谈多话
梦谈多话 2020-11-27 03:05

I have a jenkinsfile dropped into the root of my project and would like to pull in a groovy file for my pipeline and execute it. The only way that I\'ve been able to get th

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 03:31

    If your Jenkinsfile and groovy file in one repository and Jenkinsfile is loaded from SCM you have to do:

    Example.Groovy

    def exampleMethod() {
        //do something
    }
    
    def otherExampleMethod() {
        //do something else
    }
    return this
    

    JenkinsFile

    node {
        def rootDir = pwd()
        def exampleModule = load "${rootDir}@script/Example.Groovy "
        exampleModule.exampleMethod()
        exampleModule.otherExampleMethod()
    }
    

提交回复
热议问题