def exists(path) {try{sh(script:'ls -l',returnStdout: true).trim()return false} catch (err){ error "-E- Failed to run fs.exists(${path}), Exception err: ${err}"}}
07:55:59 java.io.NotSerializableException: java.lang.UNIXProcess
[Pipeline] End of Pipeline
an exception which occurred:
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2@5ac3f4cc
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@239d9620
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@239d9620
Caused: java.io.NotSerializableException: java.lang.UNIXProcess
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:926)
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.LinkedHashMap.internalWriteEntries(LinkedHashMap.java:333)
at java.util.HashMap.writeObject(HashMap.java:1363)
at sun.reflect.GeneratedMethodAccessor24.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
...
Yet another case of @NonCPS, this serializable requirements for functions is such a terrible idea, talk about tentacular requirements that destroy standard calls. They should have put recovery point function, where the context would have been saved and the script could add them as it please, this would have prevent all this @NonCPS nightmare and lead to a more standard code with standard groovy.
Add @NonCPS decorator to your functions:
@NonCPS
def MyFct() {
… do your stuff here
}
This prevent serialization of each actions into that functions.
--
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/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkins...@googlegroups.com.
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/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com.
The method named `exists` from the first email is fine and does not have any problems. Adding @NonCPS to it is incorrect as explained here and causes the “expected to call Script4.exists but wound up catching sh” warning.You mentioned using Groovy’s `String.execute()` extension method, which I suspect is the real problem, because that method creates a `java.lang.Process`, which cannot be serialized, and ends up stored as a local variable in the Pipeline, which causes the original error you posted. The Pipeline is serialized after steps execute (when using the default MAX_SURVIVABILITY durability level), which is why you don’t see the error until after the `sh` step runs.
You should not call `String.execute` or other similar Java or Groovy methods related to processes inside of a Pipeline, you should always use the `sh` or `bat` steps. Methods related to `java.lang.Process` will always execute the process on the master (which is probably not the behavior you want), and they are not allowed in the sandbox by default because users can use those methods to trivially bypass all security on the Jenkins master.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com.
--Website: http://earl-of-code.com--
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 jenkins...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com.