Can a class inside a pipeline be a subclass of the Script object?

8 views
Skip to first unread message

ZillaYT

unread,
Feb 22, 2019, 9:54:23 AM2/22/19
to Jenkins Users
I have a class, say

class Foo {
 
def fooEcho()
    echo
"Hello Foo"
 
}
}


but of course this fails if I

Foo foo = new Foo()
foo
.fooEcho()



because the Foo class doesn't know about Script echo() function. The general workaround is to do

class Foo {
 
Foo(Script s) {
   
this.script = s
 
}
 
def fooEcho() {
    script
.echo "Hello Foo"
 
}
 
def script = null
}

Foo foo = new Foo(this)
foo
.fooEcho()

But this is ugly, and it means that I have to prepend ALL normal Script calls (echo, println, stage, etc.) with "script."

Can Foo be defined as

class Foo extends Script {
 
...
}

Reply all
Reply to author
Forward
0 new messages