Re: Constructor or equivalent for "Global Variables" in libraries

2016-10-26 Thread Michael Lasevich
Yeah, I would expect it to work as well, but it simply does not.

It is probably something to do with either the way this is loaded or CPS, 
we have already seen that CPS has hard time handling some basic Groovy 
concepts like getters/setters - I was just hoping I was missing something 
obvious  :-(

-M

On Wednesday, October 26, 2016 at 9:00:40 AM UTC-7, Martina wrote:
>
> In a big standalone groovy I have
>
> class myClass {
> List myList = []
>
> public myCall (item) {
>   myList.add(item)
> }
> }
>
> I am pretty sure I have used it without the class stuff in smaller 
> snippets.
>
> Martina
>
>
>
> On Wednesday, October 26, 2016 at 8:54:59 AM UTC-6, Michael Lasevich wrote:
>>
>> No dice,
>>
>> groovy.lang.MissingPropertyException: No such property: myList for class: 
>> myListTest
>>
>>
>> -M
>>
>> On Wednesday, October 26, 2016 at 7:42:19 AM UTC-7, Martina wrote:
>>>
>>> Try the following:
>>>
>>> myList = []
>>>
>>>
>>> def call(item){
>>>   myList << item
>>> }
>>>
>>> Martina
>>>
>>> On Wednesday, October 26, 2016 at 12:24:48 AM UTC-6, Michael Lasevich 
>>> wrote:

 So, what is the proper way to initialize the fields in the "Global 
 Variables" found in the /vars dir in library code?

 I know it is supposed to be a singleton instantiated on first call, and 
 I know I can SET new fields by just setting them, but what if I want them 
 to have default value when object is created? Something like:

 // vars/myListAdder.groovy

 def myList = []


 def call(item){
   this.myList << item
 }

 I would expect this to work, but it doesn't as it cannot find myList 
 defined

 I worked around it for now by using a try/catch to initialize myList on 
 first call, but that seems wrong. There has got to be a proper way to do 
 this, but I am not sure what it is - nothing I tried seems to work

 Thanks,

 -M



-- 
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/b0efbd97-4b9b-4b73-8f07-db3ea8c5d48a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constructor or equivalent for "Global Variables" in libraries

2016-10-26 Thread Martina
In a big standalone groovy I have

class myClass {
List myList = []

public myCall (item) {
  myList.add(item)
}
}

I am pretty sure I have used it without the class stuff in smaller snippets.

Martina



On Wednesday, October 26, 2016 at 8:54:59 AM UTC-6, Michael Lasevich wrote:
>
> No dice,
>
> groovy.lang.MissingPropertyException: No such property: myList for class: 
> myListTest
>
>
> -M
>
> On Wednesday, October 26, 2016 at 7:42:19 AM UTC-7, Martina wrote:
>>
>> Try the following:
>>
>> myList = []
>>
>>
>> def call(item){
>>   myList << item
>> }
>>
>> Martina
>>
>> On Wednesday, October 26, 2016 at 12:24:48 AM UTC-6, Michael Lasevich 
>> wrote:
>>>
>>> So, what is the proper way to initialize the fields in the "Global 
>>> Variables" found in the /vars dir in library code?
>>>
>>> I know it is supposed to be a singleton instantiated on first call, and 
>>> I know I can SET new fields by just setting them, but what if I want them 
>>> to have default value when object is created? Something like:
>>>
>>> // vars/myListAdder.groovy
>>>
>>> def myList = []
>>>
>>>
>>> def call(item){
>>>   this.myList << item
>>> }
>>>
>>> I would expect this to work, but it doesn't as it cannot find myList 
>>> defined
>>>
>>> I worked around it for now by using a try/catch to initialize myList on 
>>> first call, but that seems wrong. There has got to be a proper way to do 
>>> this, but I am not sure what it is - nothing I tried seems to work
>>>
>>> Thanks,
>>>
>>> -M
>>>
>>>

-- 
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/104aa9d2-7c6d-4b4c-88a8-34202c8b8862%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constructor or equivalent for "Global Variables" in libraries

2016-10-26 Thread Michael Lasevich
No dice,

groovy.lang.MissingPropertyException: No such property: myList for class: 
myListTest


-M

On Wednesday, October 26, 2016 at 7:42:19 AM UTC-7, Martina wrote:
>
> Try the following:
>
> myList = []
>
>
> def call(item){
>   myList << item
> }
>
> Martina
>
> On Wednesday, October 26, 2016 at 12:24:48 AM UTC-6, Michael Lasevich 
> wrote:
>>
>> So, what is the proper way to initialize the fields in the "Global 
>> Variables" found in the /vars dir in library code?
>>
>> I know it is supposed to be a singleton instantiated on first call, and I 
>> know I can SET new fields by just setting them, but what if I want them to 
>> have default value when object is created? Something like:
>>
>> // vars/myListAdder.groovy
>>
>> def myList = []
>>
>>
>> def call(item){
>>   this.myList << item
>> }
>>
>> I would expect this to work, but it doesn't as it cannot find myList 
>> defined
>>
>> I worked around it for now by using a try/catch to initialize myList on 
>> first call, but that seems wrong. There has got to be a proper way to do 
>> this, but I am not sure what it is - nothing I tried seems to work
>>
>> Thanks,
>>
>> -M
>>
>>

-- 
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/9b253148-84ea-479c-b5ba-3ace633c60bb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Constructor or equivalent for "Global Variables" in libraries

2016-10-26 Thread Martina
Try the following:

myList = []


def call(item){
  myList << item
}

Martina

On Wednesday, October 26, 2016 at 12:24:48 AM UTC-6, Michael Lasevich wrote:
>
> So, what is the proper way to initialize the fields in the "Global 
> Variables" found in the /vars dir in library code?
>
> I know it is supposed to be a singleton instantiated on first call, and I 
> know I can SET new fields by just setting them, but what if I want them to 
> have default value when object is created? Something like:
>
> // vars/myListAdder.groovy
>
> def myList = []
>
>
> def call(item){
>   this.myList << item
> }
>
> I would expect this to work, but it doesn't as it cannot find myList 
> defined
>
> I worked around it for now by using a try/catch to initialize myList on 
> first call, but that seems wrong. There has got to be a proper way to do 
> this, but I am not sure what it is - nothing I tried seems to work
>
> Thanks,
>
> -M
>
>

-- 
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/c8f0d36b-4a50-4959-b392-552d294ed0f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.