Shared library function cannot call other shared library function in separate file if called function uses "writeFile"

563 views
Skip to first unread message

David Karr

unread,
Feb 7, 2020, 3:51:42 PM2/7/20
to Jenkins Users
The statement I make in the subject doesn't make sense, but I don't know how else to describe it.

I'm working on a set of builds using scripted pipelines.  Our Jenkinsfiles are very short, all of the build logic is in the shared library.  In the "main" shared library function, I'm trying to call another function defined in another "vars" class.  We have many of these already.  In this called function, I have a call to the "writeFile" pipeline step to create a temporary file used by a shell script called immediately after that.  This is the only place anywhere in our builds that we call "writeFile".

When I run the build, I get this very unhelpful message:

Jenkins Job Failed due to Exception : org.codehaus.groovy.control.ErrorCollector

There is literally no other information provided, except for the log lines that come before it.  I found that an echo statement that is called before this suspect function is called is emitted in the log.  An echo statement as the first line of the "call()" method of the function being called is NOT emitted in the log. Somehow the act of calling the function makes it die, with no explanation.

So, I tried a workaround.  In the calling script file, I added a "def" at the end of the file, to define an "inline function" with almost the same name as the "vars" function name.  I copied the entire body of the "call()" method of the vars function into that inline function.  I replaced the call to the vars function with the call to the inline function.  It worked on the first try.

Any ideas what might cause this?

Reinhold Füreder

unread,
Feb 8, 2020, 11:43:56 AM2/8/20
to Jenkins Users
Hi David,

I think that could be related to https://issues.jenkins-ci.org/browse/JENKINS-50736, because there is a pipeline basic step called 'writeFile' (see https://jenkins.io/doc/pipeline/steps/workflow-basic-steps/#writefile-write-file-to-workspace), but maybe Jesse Glick or Andrew Bayer can shed some more light on this issue...

HTH Reinhold


Von: jenkins...@googlegroups.com <jenkins...@googlegroups.com> im Auftrag von David Karr <davidmic...@gmail.com>
Gesendet: Freitag, 7. Februar 2020 21:51
An: Jenkins Users <jenkins...@googlegroups.com>
Betreff: Shared library function cannot call other shared library function in separate file if called function uses "writeFile"
 
--
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/3119e9f3-e6a8-4fa6-861a-76c9358ab300%40googlegroups.com.

Jan Monterrubio

unread,
Feb 8, 2020, 12:21:30 PM2/8/20
to jenkins...@googlegroups.com
Yeah you’re probably getting namespace collisions. This happened to me trying to make a logging function called ‘error’ as well. 

David Karr

unread,
Feb 8, 2020, 8:16:36 PM2/8/20
to Jenkins Users
I think you've both misunderstood what I'm saying, or I'm not being clear enough.

I'm not writing to write a function named "writeFile", I'm just calling that pipeline step from the function.  All of the function names I'm creating are definitely unique.  If I call the "vars" function that calls "writeFile", I get the seemingly generic error with no other information.  If I instead call the inline function with contents identical to the "vars" function, it works fine.

Reinhold Füreder

unread,
Feb 11, 2020, 2:07:24 AM2/11/20
to jenkins...@googlegroups.com

Weird. And sorry for misunderstanding you.

 

There might be a stacktrace in the Jenkins log file (hopefully). Or you could try catch all exceptions in your scripted pipeline to get some more details…

 

I just tried to reproduce your problem (or the one I now think you are describing), but unfortunately it works like a charm 😲

 

Cu Reinhold

--

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.

David Karr

unread,
Feb 11, 2020, 3:00:37 PM2/11/20
to Jenkins Users
The problem is not that we're failing to catch an exception, the problem is that the exceptions aren't telling us anything.

The following occurs at the end of the build log:
an exception which occurred:
       
in field org.codehaus.groovy.control.MultipleCompilationErrorsException.collector
       
in object org.codehaus.groovy.control.MultipleCompilationErrorsException@56f542c3
       
in field com.cloudbees.groovy.cps.Outcome.abnormal
       
in object com.cloudbees.groovy.cps.Outcome@58839b2d
       
in field org.jenkinsci.plugins.workflow.cps.CpsBodyExecution.outcome
       
in object org.jenkinsci.plugins.workflow.cps.CpsBodyExecution@2fab07a3
       
in field org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter.this$0
       
in object org.jenkinsci.plugins.workflow.cps.CpsBodyExecution$SuccessAdapter@13992864
       
in field com.cloudbees.groovy.cps.impl.CallEnv.returnAddress
       
in object com.cloudbees.groovy.cps.impl.FunctionCallEnv@4b24116
       
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
       
in object com.cloudbees.groovy.cps.impl.TryBlockEnv@2c520b87
       
in field com.cloudbees.groovy.cps.impl.CallEnv.caller
       
in object com.cloudbees.groovy.cps.impl.ClosureCallEnv@2489377e
       
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
       
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@2c3884bf
       
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
       
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@bf6e705
       
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
       
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@748ef562
       
in field com.cloudbees.groovy.cps.impl.ProxyEnv.parent
       
in object com.cloudbees.groovy.cps.impl.BlockScopeEnv@3758738
       
in field com.cloudbees.groovy.cps.impl.CpsClosureDef.capture
       
in object com.cloudbees.groovy.cps.impl.CpsClosureDef@41614515
       
in field com.cloudbees.groovy.cps.impl.CpsClosure.def
       
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@1cb035e0
       
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
       
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@2b6c7a88
       
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@2b6c7a88
Caused: java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector
        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)
        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.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.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.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.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.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.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.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.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:344)
        at java
.util.HashMap.internalWriteEntries(HashMap.java:1790)
        at java
.util.HashMap.writeObject(HashMap.java:1363)
        at sun
.reflect.GeneratedMethodAccessor405.invoke(Unknown Source)
        at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java
.lang.reflect.Method.invoke(Method.java:498)
        at org
.jboss.marshalling.reflect.SerializableClass.callWriteObject(SerializableClass.java:273)
        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.lambda$writeObject$0(RiverWriter.java:144)
        at org
.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
        at org
.jenkinsci.plugins.workflow.support.pickles.serialization.RiverWriter.writeObject(RiverWriter.java:143)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:477)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:453)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgramIfPossible(CpsThreadGroup.java:440)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:367)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
        at org
.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
        at org
.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
        at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
        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:511)
        at java
.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java
.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java
.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java
.lang.Thread.run(Thread.java:748)
Enter code here...

To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.

Reinhold Füreder

unread,
Feb 12, 2020, 12:57:31 AM2/12/20
to jenkins...@googlegroups.com

Hi David,

 

I see what you mean with “that the exceptions aren't telling us anything”: Unfortunately I am also not sure if “Caused: java.io.NotSerializableException: org.codehaus.groovy.control.ErrorCollector” may indicate that there is some serializiation problem or e.g. some @NonCPS methods calling normal methods, or if this is just a side effect of another problem (i.e. the actual root cause)…

Since the most trivial use case just worked for me, maybe you can post some more code (and context) here; otherwise it will be very difficult to provide any further assistenance…

 

Sorry,

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/cdcd32cd-40c5-4643-be0f-c52d02cd4ed8%40googlegroups.com.

David Karr

unread,
Feb 13, 2020, 1:26:53 PM2/13/20
to Jenkins Users
I was blocked on this for a couple days because of some other related issues.

I believe I have now verified that the cause of this problem is the "writeFile" pipeline step, but I don't know why.  I verified this because I was able to refactor the vars method to not use "writeFile" at all. A "sh" step that occurs just before this has been augmented to generate the data I need directly in the pipeline, and it pipes the output directly to the file, instead of using "writeFile".

So, for me, the issue is resolved.  I'm just going to be wary in the future about implementing Jenkins pipeline scripts that use "writeFile", and try to do it in a different way.

After I changed the Jenkins script to use the vars method again, it works perfectly fine.
Reply all
Reply to author
Forward
0 new messages