Getting "java.io.NotSerializableException" exception in Jenkins pipeline, groovy.

2,264 views
Skip to first unread message

Ganesh Kumbhar

unread,
Nov 14, 2016, 12:13:35 AM11/14/16
to Jenkins Users
Hello All,

I am new to Jenkins pipeline and recently started to use it for my project build.

So, from Jenkins file I am calling a method from other .groovy file which is simple script having some functions defined and in those functions I am creating antbuilder object -> "@Field AntBuilder antBuilder = new AntBuilder()"
But the problem is, I am not able to call any ant targets using antbuilder object, simply calling echo using this object like -> " antBuilder.echo 'print statement' "  gives "NotSerializableException"exception.

java.io.NotSerializableException: org.apache.tools.ant.taskdefs.Echo
	at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
	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.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.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)

So please guide me to resolve this problem if anyone had faced this issue or have any idea about it.
Any help is appreciated!
Thank you very much!
Ganesh K.

Thomas Keller

unread,
Nov 14, 2016, 5:21:05 AM11/14/16
to Jenkins Users

IIRC objects used in pipelines need to be able to get serialized, because the build should be pausable and resumable at any time. Try to refactor the AntBuilder object creation and call into a groovy method and annotate this method with @NonCPS

Donald Morton

unread,
Nov 14, 2016, 5:29:33 PM11/14/16
to Jenkins Users

Ganesh Kumbhar

unread,
Nov 16, 2016, 2:40:12 AM11/16/16
to jenkins...@googlegroups.com
Thanks a lot Thomas & Donald for your reply .. I would try these suggestions & I guess this should be working!

Actually now I am getting error before going to this stage, don't know why but same block of code behaving weird now, it was working file earlier :( 
problem in loading a file!

Inline image 2a
As you see here, it's not able to load groovy file, which was working the day before! 

Please let me know if you have any idea ? Details as below :  

My Job configuration : 
Inline image 1
here, runErtools*() method is defined in Jenkins File which loads another groovy file as below : 

void runErtoolsRegressionTests(def mks_host, def si_port, def im_port, def autotest_dev_cp, def autotest_pv_cp) {
ws("D:\\ci_ws\\$env.JOB_NAME") {
git branch: 'regression-tests', url: 'http://frjenkins001.auto.contiwan.com:8080/tools/ertools'
def curDir = pwd()
println curDir
def regressionTests = load("RegressionTestScripts/ertools_regression_test.groovy")
print regressionTests
regressionTests.runRegressionTests(mks_host,si_port,im_port,autotest_dev_cp,autotest_pv_cp, $env.JOB_NAME)
      }
}
Thanks & Regards,
Ganesh.


--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/TV0Ea88j6iA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/2b760da3-e4d8-4da4-a554-dbfca8576d86%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages