Loading class in Jenkins : No such property for class -
i'm trying load class file in jenkins pipeline. here's code :
pipeline{ agent none stages{ stage('testclass'){ agent{ label 'testslave' } steps{ script{ def cl = load 'c:\\users\\test\\desktop\\testclass.groovy' def b = cl.b echo b.greet("test") } } } }
here's class file :
class a{ def greet(name){ return "greet a: $name!" } } class b{ def greet(name){ return "greet b: $name!" } } // method have nice access create class name object getproperty(string name){ return this.getclass().getclassloader().loadclass(name).newinstance(); } return
when build pipeline, gives me
groovy.lang.missingpropertyexception: no such property: b class...
someone knows why? thx.
it worked with: def b = cl.getproperty('b') !
Comments
Post a Comment