2017-08-14 33 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')!

相關問題