Why I get this java.io.NotSerializableException error

17 views
Skip to first unread message

Kristian

unread,
Jan 13, 2017, 10:00:53 AM1/13/17
to jenkins...@googlegroups.com
Hi,

I am just trying to create a jenkins pipeline library and I just
started with a small test script (test.groovy):

///////////////////////////
package com.somescripts.groovy;

class test{
def giveMeTest() {
println "giveMeTest tested successfully :)"
}
}
///////////////////////////

I am starting this script in a Jenkinsfile like this:

///////////////////////////
@Library('GroovyPipeline')

import com.somescripts.groovy.*;

def t = new com.somescripts.groovy.test();
t.giveMeTest();
///////////////////////////

But I am getting this error:

///////////////////////////
java.io.NotSerializableException: com.somescripts.groovy.test
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:344)
at java.util.HashMap.internalWriteEntries(HashMap.java:1785)
///////////////////////////

It does not help when I change my class definition to

class test implements Serializable { ....

So my question: Why I am getting this error?

Indra Gunawan (ingunawa)

unread,
Jan 13, 2017, 12:39:40 PM1/13/17
to jenkins...@googlegroups.com
Add @NonCPS to “giveMeTest()”:


@NonCPS def giveMeTest() { }
--
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-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAO5HUhNhXC3CK02vF99VkQe6s5HXpc%2B5BGH0v1LnjcK_s%2BQ%3DKA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Reply all
Reply to author
Forward
0 new messages