我正在尝试在Jenkins管道中加载一个类文件。这是代码:
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")
}
}
}
}
这是我的班级文件:
class A{
def greet(name){
return "greet from A: $name!"
}
}
class B{
def greet(name){
return "greet from B: $name!"
}
}
// this method just to have nice access to create class by name
Object getProperty(String name){
return this.getClass().getClassLoader().loadClass(name).newInstance();
}
return this
当我构建管道时,它给了我
groovy.lang.MissingPropertyException:没有这样的属性:B代表类......
有人知道为什么吗? THX。
答案 0 :(得分:0)
它适用于:def b = cl.getProperty('B')!