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 org.jboss.marshalling.river.RiverObjectOutputStream.writeObjectOverride(RiverObjectOutputStream.java:179)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:343)
at com.cloudbees.groovy.cps.SerializableScript.writeObject(SerializableScript.java:26)
at sun.reflect.GeneratedMethodAccessor283.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.doWriteSerializableObject(RiverMarshaller.java:967)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:967)
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 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.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1032)
at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:988)
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:854)
at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:58)
at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:111)
at org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:132)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:429)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:408)
at org.jenkinsci.plugins.workflow.cps.CpsStepContext$3.onSuccess(CpsStepContext.java:488)
at org.jenkinsci.plugins.workflow.cps.CpsStepContext$3.onSuccess(CpsStepContext.java:484)
at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution$4$1.run(CpsFlowExecution.java:627)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$1.run(CpsVmExecutorService.java:35)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: an exception which occurred:
in field delegate
in field closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@470056de
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.