How to import a file of classes in a Jenkins Pipeline?

后端 未结 1 1646
眼角桃花
眼角桃花 2020-12-21 18:02

I have a file that contains classes. Example :


abstract class TestBase
{
    String name
    abstract def fTest()

    def bobby(){
        return \"b         


        
相关标签:
1条回答
  • you can do like this:

    Classes.groovy

    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
    

    pipeline:

    node{
        def cl = load 'Classes.groovy'
        def a = cl.A
        echo a.greet("world A")
        def b = cl.B
        echo b.greet("world B")
    }
    
    0 讨论(0)
提交回复
热议问题