2017-08-14 62 views
0

我想加载我的詹金斯管道中的类文件。下面的代码:在詹金斯上课:没有这样的属性类


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:没有这样的属性:乙类...


有人知道这是为什么?谢谢。

回答

0

它适用于:def b = cl.getProperty('B')!

相关问题