Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-40109

Compilation error in shared library/global variable produces java.io.NotSerializableException org.codehaus.groovy.control.ErrorCollector

    XMLWordPrintable

    Details

    • Similar Issues:
    • Released As:
      Pipeline: Groovy 2.57 and Pipeline: Shared Groovy Libraries 2.12

      Description

      I am trying to run the latest new feature to get output from sh command. Here is my code:

            _  emails = sh (
                  script: "git --no-pager show -s --format='%ae'   ${commit_hash}"
                  returnStdout: true
              )
              echo "emails: ${emails}"_
      

      I am getting back an error:

      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.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.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.TreeMap.writeObject(TreeMap.java:2434)
      	at sun.reflect.GeneratedMethodAccessor276.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: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:371)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.saveProgram(CpsThreadGroup.java:355)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:309)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$000(CpsThreadGroup.java:77)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:186)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:184)
      	at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:47)
      	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:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745)
      Caused by: an exception which occurred:
      	in field collector
      	in field v
      	in field returnAddress
      	in field e
      	in field program
      	in field threads
      	in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@67742400
      Finished: FAILURE
      

      When I do not use returnStdout, the code works find executing the command (of course not returning anything)
      Any help there?
      Thanks

        Attachments

          Issue Links

            Activity

            Hide
            ulidtko Max M added a comment -

            Hey Andrew Bayer!

            I've succeeded in minimizing the reproducing config for my case:

            node('build-server') {
              gitlabCommitStatus {
                // try {
                  stage('CI fail test') {
                    sh('echo IP=10.0.0.1 > test_env')
                    load('test_env')
                  }
                // }
                // catch (java.lang.Throwable error) {
                //   println "exception caught"
                //   println error
                //   throw error
                // }
              }
            }
            

            It seems that gitlabCommitStatus wrap is essential here: without it, exception details are clear and informative in the log. With it, I get NotSerializableException as above.

            The exact compile error trigger is less important: here, it's that IP=10.0.0.1 isn't valid Groovy. Of course, this could've been a legitimate Groovy CI module load, perhaps with a syntax error as well.

            The commented try-catch is a workaround I found which helps to see the actual compile error.

            Might it be a gitlabCommitStatus bug?.. I don't even know which plugin is that from, sorry about that.

            Anyway, hope this helps!

            Show
            ulidtko Max M added a comment - Hey Andrew Bayer ! I've succeeded in minimizing the reproducing config for my case: node( 'build-server' ) { gitlabCommitStatus { // try { stage( 'CI fail test' ) { sh( 'echo IP=10.0.0.1 > test_env' ) load( 'test_env' ) } // } // catch (java.lang.Throwable error) { // println "exception caught" // println error // throw error // } } } It seems that gitlabCommitStatus wrap is essential here: without it, exception details are clear and informative in the log. With it, I get NotSerializableException as above. The exact compile error trigger is less important: here, it's that IP=10.0.0.1 isn't valid Groovy. Of course, this could've been a legitimate Groovy CI module load, perhaps with a syntax error as well. The commented try-catch is a workaround I found which helps to see the actual compile error. Might it be a gitlabCommitStatus bug?.. I don't even know which plugin is that from, sorry about that. Anyway, hope this helps!
            Hide
            abayer Andrew Bayer added a comment -

            Yeah, it does appear to be an issue with the Gitlab step (which is from the gitlab plugin, FYI) trying to persist the result of executing the body. I’d advise opening a new JIRA against the gitlab plugin for that.

            Show
            abayer Andrew Bayer added a comment - Yeah, it does appear to be an issue with the Gitlab step (which is from the gitlab plugin, FYI) trying to persist the result of executing the body. I’d advise opening a new JIRA against the gitlab plugin for that.
            Hide
            ulidtko Max M added a comment -

            Reported as JENKINS-50740.

            Show
            ulidtko Max M added a comment - Reported as JENKINS-50740 .
            Hide
            dnusbaum Devin Nusbaum added a comment -
            Show
            dnusbaum Devin Nusbaum added a comment - A fix is in review here: https://github.com/jenkinsci/workflow-cps-global-lib-plugin/pull/53 .
            Hide
            dnusbaum Devin Nusbaum added a comment -

            Fixes released in Pipeline: Groovy version 2.57 and Pipeline: Shared Groovy Libraries version 2.12. Thanks Rudolf-Walter Kiss-Szakacs!

            Show
            dnusbaum Devin Nusbaum added a comment - Fixes released in Pipeline: Groovy version 2.57 and Pipeline: Shared Groovy Libraries version 2.12. Thanks Rudolf-Walter Kiss-Szakacs !

              People

              • Assignee:
                rudolfwg Rudolf-Walter Kiss-Szakacs
                Reporter:
                sshkolni Sasha Shkolnik
              • Votes:
                7 Vote for this issue
                Watchers:
                14 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: