How do you load a groovy file and execute it

后端 未结 5 621
梦谈多话
梦谈多话 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:54

    Very useful thread, had the same problem, solved following you.

    My problem was: Jenkinsfile -> call a first.groovy -> call second.groovy

    Here my solution:

    Jenkinsfile

    node {
      checkout scm
      //other commands if you have
    
      def runner = load pwd() + '/first.groovy'
      runner.whateverMethod(arg1,arg2)
    }
    

    first.groovy

    def first.groovy(arg1,arg2){
      //whatever others commands
    
      def caller = load pwd() + '/second.groovy'
      caller.otherMethod(arg1,arg2)
    }
    

    NB: args are optional, add them if you have or leave blank.

    Hope this could helps further.

提交回复
热议问题