Dynamically load a groovy class and invoke a method in pipeline script

4.9k Views Asked by At

I have developed groovy classes in IntelliJ IDE, I want to instantiate one of these classes in 'Pipeline script' of Pipeline plugin in Jenkins. I tried to follow the examples of 'Eval.me' and class.forName

Sample

package com.mycomp.tmo

/**
 * Created by
 */
public void callMe(){
    println("Hello World !")
}


def e = "callMe"
def cl = Class.forName("com.mycomp.tmo.Sample")
println(Eval.me("${c1} (${e})"))

Tried Below as well:

String cls = 'D:\\Users\\b\\IdeaProjects\\Automation\\src\\com\\mycomp\\tmo\\DBConnectionManager'

def map = ['person': ${cls}]
map['person'].newInstance()
1

There are 1 best solutions below

4
Tim On

I think the post I asked two weeks ago can answer your question. Create resusable jenkins pipeline script