Re: Pipeline shared libraries, can I have a constructor when I don't explicitly declare the enclosing class?

2016-11-08 Thread thomas . lehmann
When you define a class then you can write a function that returns an 
instance of that class.
Just the way you write it ... you do not write a class ... you get an 
instance of the library which contains functions

class Foo {
def sum(a, b) {
return a + b
}
}

def createFoo() {
   return new Foo()
}

def sum(a, b){
return a + b
}

return this;

Assume the file is foo.groovy you can do then:

def fooApi = load pwd() + '/foo.groovy'
echo "10+20=" + fooApi.sum(10, 20).toString()
def foo = fooApi.createFoo()
echo "10+20=" + foo.sum(10, 20).toString()

kind of ...
I hope this helps ...


On Monday, November 7, 2016 at 10:54:56 PM UTC+1, Jonathan Hodgson wrote:
>
> Hi,
>
> I'm setting up a folder library as per here.
>
> Now in one of their examples they talk about not declaring the enclosing 
> class (so as to allow access to steps)
>
> This works fine, in the file MyClass.groovy
>
> @package my.package
>
>
>
> def myMethod(data)
> {
> // do stuff with data
> }
>
>
> return this
>
>
> I can declare an instance of the class and use it with 
>
> method = new my.package.MyClass()
>
>
> myClass.myMethod(my_data)
>
>
> But I cannot create a contructor, is there a way to do this?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/651ec37a-a9b9-4100-9602-a9a93aa40871%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Pipeline shared libraries, can I have a constructor when I don't explicitly declare the enclosing class?

2016-11-07 Thread Jonathan Hodgson
Hi,

I'm setting up a folder library as per here.

Now in one of their examples they talk about not declaring the enclosing 
class (so as to allow access to steps)

This works fine, in the file MyClass.groovy

@package my.package



def myMethod(data)
{
// do stuff with data
}


return this


I can declare an instance of the class and use it with 

method = new my.package.MyClass()


myClass.myMethod(my_data)


But I cannot create a contructor, is there a way to do this?

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/3c86d57e-4186-43df-8288-e5f4c552c17e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.