Re: Pipeline Groovy Madness

2016-10-14 Thread Brian Ray
Keep an eye on JENKINS-35390 
.

Though the other day I optimistically tried to use Groovy's AST transform 
@Immutable 
 
on a class ... should've known that would not play nicely with the CPS 
transforms.

On Friday, October 14, 2016 at 8:33:49 AM UTC-7, Jonathan Hodgson wrote:
>
>
>
> On Friday, October 14, 2016 at 1:47:24 PM UTC+1, Daniel Beck wrote:
>>
>>
>> > On 14.10.2016, at 13:25, Jonathan Hodgson  wrote: 
>> > 
>> > All I've done is move that one line, and for the record at the moment 
>> it's being called without OSX being active, so nothing inside that first if 
>> statement is being executed (though it shouldn't cause any problems even if 
>> its was) 
>> > 
>> > I'm confused, and frustrated. Any help greatly appreciated. 
>>
>> The last statement in a Groovy method is the implicit return value. 
>> `find` returns a LinkedHashMap$Entry, it gets returned from the method 
>> call, and it breaks due to CPS serialization. 
>>
>> Thanks Daniel, I'm still finding my feet with Groovy, throw in the CPS 
> issues plus other pipeline job problems (e.g. the lack of working file 
> parameters) and I find myself going round and round until I don't know 
> which way is up, down or sideways.
>
> Changing things to
>
> @NonCPS def isPlatformActive(platform, active_builds)
> {
> found = (null != active_builds[platform].find { it.value == true } )
> found
> }
>
> Seems to have fixed this issue
>
>
>> Regarding the regression, likely due to 
>> https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Groovy+Plugin#PipelineGroovyPlugin-2.14%28Sep07%2C2016%29
>>  
>>
>>
> Thanks again.
>
> It's the lack of consistency which is driving me nuts, things work in one 
> place, but not another, or they work with one version, but not the next. It 
> makes debugging so hard. 
>
> And for the love of God could somebody please implement some useful error 
> messages!?
>
> Things should either work, or not work with a suitable error message.
>
> I don't know how difficult it would be, but a lint style checker that 
> would pick up forbidden constructs in CPS functions would be nice too... 
> but there I'm getting into dreamland I fear.
>

-- 
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/02e75241-3f24-4e97-b446-aa145870995a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pipeline Groovy Madness

2016-10-14 Thread Jonathan Hodgson


On Friday, October 14, 2016 at 1:47:24 PM UTC+1, Daniel Beck wrote:
>
>
> > On 14.10.2016, at 13:25, Jonathan Hodgson  > wrote: 
> > 
> > All I've done is move that one line, and for the record at the moment 
> it's being called without OSX being active, so nothing inside that first if 
> statement is being executed (though it shouldn't cause any problems even if 
> its was) 
> > 
> > I'm confused, and frustrated. Any help greatly appreciated. 
>
> The last statement in a Groovy method is the implicit return value. `find` 
> returns a LinkedHashMap$Entry, it gets returned from the method call, and 
> it breaks due to CPS serialization. 
>
> Thanks Daniel, I'm still finding my feet with Groovy, throw in the CPS 
issues plus other pipeline job problems (e.g. the lack of working file 
parameters) and I find myself going round and round until I don't know 
which way is up, down or sideways.

Changing things to

@NonCPS def isPlatformActive(platform, active_builds)
{
found = (null != active_builds[platform].find { it.value == true } )
found
}

Seems to have fixed this issue


> Regarding the regression, likely due to 
> https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Groovy+Plugin#PipelineGroovyPlugin-2.14%28Sep07%2C2016%29
>  
>
>
Thanks again.

It's the lack of consistency which is driving me nuts, things work in one 
place, but not another, or they work with one version, but not the next. It 
makes debugging so hard. 

And for the love of God could somebody please implement some useful error 
messages!?

Things should either work, or not work with a suitable error message.

I don't know how difficult it would be, but a lint style checker that would 
pick up forbidden constructs in CPS functions would be nice too... but 
there I'm getting into dreamland I fear.

-- 
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/1ae9dabb-9b29-43a0-a440-371bb79695f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Pipeline Groovy Madness

2016-10-14 Thread Daniel Beck

> On 14.10.2016, at 13:25, Jonathan Hodgson  wrote:
> 
> All I've done is move that one line, and for the record at the moment it's 
> being called without OSX being active, so nothing inside that first if 
> statement is being executed (though it shouldn't cause any problems even if 
> its was)
> 
> I'm confused, and frustrated. Any help greatly appreciated.

The last statement in a Groovy method is the implicit return value. `find` 
returns a LinkedHashMap$Entry, it gets returned from the method call, and it 
breaks due to CPS serialization.

http://groovy-lang.org/semantics.html#_optional_return_keyword

Regarding the regression, likely due to 
https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Groovy+Plugin#PipelineGroovyPlugin-2.14%28Sep07%2C2016%29

-- 
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/B32FE469-5ECF-4533-8B3C-D868007700DE%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.


Pipeline Groovy Madness

2016-10-14 Thread Jonathan Hodgson
Hi,

I'm trying to get some Groovy code working in the pipeline.

The code used to work fine, somewhere in the endless stream of updates of 
jenkins and plugins, it stopped.

It used to look like this (I've stripped the bits that do actual work out 
for brevity)

@NonCPS def isPlatformActive(platform, active_builds)
{
found = active_builds[platform].find { it.value == true } 
found
}

def buildAll(build_types, active_builds, plugin_formats)
{
stage ("Building And Testing") {
platform_builders = [:]
something_failed = false
failed_message = ""
if (isPlatformActive("OSX", active_builds))
{
platform_builders ["Mac"] = {
node ("XCode")
{
ws (project_workspace) {
echo "Substage running on OSX"
}
}
}
}
if (isPlatformActive("Win32", active_builds) || 
isPlatformActive("Win64", active_builds))
{
platform_builders ["Windows"] = { 
node ("VS2013")
{
ws (project_workspace) {
echo "Substage running on Windows"
}
}
}
}
   }
}

And it used to work.

But then when I came back to it, I found I was getting an exception
An Error Occured java.io.NotSerializableException: 
java.util.LinkedHashMap$Entry

So, putting this down to the known issue with Groovy in the pipeline I 
changed isPlatformActive to a @NonCPS function, which worked find so long 
as the second if statement was commented out, but not when I uncommented it.

After further experimentation I've found that this works

@NonCPS def isPlatformActive(platform, active_builds)
{
found = active_builds[platform].find { it.value == true } 
found
}

def buildAll(build_types, active_builds, plugin_formats)
{
stage ("Building And Testing") {
platform_builders = [:]
something_failed = false
failed_message = ""
isPlatformActive("Win32", active_builds) // Just in here to test 
nothing goes wrong - it doesn't
if (isPlatformActive("OSX", active_builds))
{
platform_builders ["Mac"] = {
node ("XCode")
{
ws (project_workspace) {
echo "Substage running on OSX"
}
}
}
}
   }
}

But this doesn't
@NonCPS def isPlatformActive(platform, active_builds)
{
found = active_builds[platform].find { it.value == true } 
found
}

def buildAll(build_types, active_builds, plugin_formats)
{
stage ("Building And Testing") {
platform_builders = [:]
something_failed = false
failed_message = ""
   if (isPlatformActive("OSX", active_builds))
{
platform_builders ["Mac"] = {
node ("XCode")
{
ws (project_workspace) {
echo "Substage running on OSX"
}
}
}
}
isPlatformActive("Win32", active_builds) // Just in here to test 
nothing goes wrong - IT DOES
   }
}


I get

java.io.NotSerializableException: java.util.LinkedHashMap$Entry
at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at 
org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at 
org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at 
org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at 
org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
at java.util.HashMap.writeObject(HashMap.java:1129)
at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at 
org.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:271)
at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:976)
at 
org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
at 
org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at 
org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at 
org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
at 
org.jboss.marshalling.MarshallerObjectOutputStream.writeObjectOverride(MarshallerObjectOutputStream.java:50)
at