java.io.NotSerializableException: java.lang.UNIXProcess

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

java.io.NotSerializableException: java.lang.UNIXProcess

chencho m-a
Hi all, 

I have a (I hope) stupid issue that i am not able to solve

I am calling to a method that only call a bash script like this.


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}"}
}



And I am always getting this exception

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)
...


Any clue?

Jenkins 2.222.4

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

RE: java.io.NotSerializableException: java.lang.UNIXProcess

Jérôme Godbout

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.

 

From: [hidden email] <[hidden email]> On Behalf Of chencho m-a
Sent: June 8, 2020 5:19 AM
To: Jenkins Users <[hidden email]>
Subject: java.io.NotSerializableException: java.lang.UNIXProcess

 

Hi all, 

 

I have a (I hope) stupid issue that i am not able to solve

 

I am calling to a method that only call a bash script like this.

 


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}"}

}

 

 

And I am always getting this exception

 

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 [hidden email]
       
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
       
in object [hidden email]
       
in object [hidden email]
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)

...

 

 

Any clue?

Jenkins 2.222.4

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/YQBPR0101MB1074933282C997665C2DF158CD850%40YQBPR0101MB1074.CANPRD01.PROD.OUTLOOK.COM.
Reply | Threaded
Open this post in threaded view
|

Re: java.io.NotSerializableException: java.lang.UNIXProcess

chencho m-a
I altready tried this, with this output.

expected to call Script4.exists but wound up catching sh; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/

NOTE: if I use execute().text, instead of sh, it works fine.




El lunes, 8 de junio de 2020, 19:42:15 (UTC+2), Jérôme Godbout escribió:

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.

 

From: <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com> On Behalf Of chencho m-a
Sent: June 8, 2020 5:19 AM
To: Jenkins Users <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com>
Subject: java.io.NotSerializableException: java.lang.UNIXProcess

 

Hi all, 

 

I have a (I hope) stupid issue that i am not able to solve

 

I am calling to a method that only call a bash script like this.

 


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}"}

}

 

 

And I am always getting this exception

 

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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">org.jenkinsci.plugins.workflow.cps.CpsClosure2@5ac3f4cc
       
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
       
in object <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@239d9620
       
in object <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">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)

...

 

 

Any clue?

Jenkins 2.222.4

 

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="V5SE6ueABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;"> https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: java.io.NotSerializableException: java.lang.UNIXProcess

slide
Can you share your Jenkinsfile? There may be some contextual information that would help people help you.

On Mon, Jun 8, 2020 at 3:08 PM chencho m-a <[hidden email]> wrote:
I altready tried this, with this output.

expected to call Script4.exists but wound up catching sh; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/

NOTE: if I use execute().text, instead of sh, it works fine.




El lunes, 8 de junio de 2020, 19:42:15 (UTC+2), Jérôme Godbout escribió:

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.

 

From: [hidden email] <[hidden email]> On Behalf Of chencho m-a
Sent: June 8, 2020 5:19 AM
To: Jenkins Users <[hidden email]>
Subject: java.io.NotSerializableException: java.lang.UNIXProcess

 

Hi all, 

 

I have a (I hope) stupid issue that i am not able to solve

 

I am calling to a method that only call a bash script like this.

 


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}"}

}

 

 

And I am always getting this exception

 

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)

...

 

 

Any clue?

Jenkins 2.222.4

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com.
Reply | Threaded
Open this post in threaded view
|

Re: java.io.NotSerializableException: java.lang.UNIXProcess

Devin Nusbaum
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.

On Jun 8, 2020, at 18:57, Slide <[hidden email]> wrote:

Can you share your Jenkinsfile? There may be some contextual information that would help people help you.

On Mon, Jun 8, 2020 at 3:08 PM chencho m-a <[hidden email]> wrote:
I altready tried this, with this output.

expected to call Script4.exists but wound up catching sh; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/

NOTE: if I use execute().text, instead of sh, it works fine.




El lunes, 8 de junio de 2020, 19:42:15 (UTC+2), Jérôme Godbout escribió:

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.

 

From: [hidden email] <[hidden email]> On Behalf Of chencho m-a
Sent: June 8, 2020 5:19 AM
To: Jenkins Users <[hidden email]>
Subject: java.io.NotSerializableException: java.lang.UNIXProcess

 

Hi all, 

 

I have a (I hope) stupid issue that i am not able to solve

 

I am calling to a method that only call a bash script like this.

 


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}"}

}

 
 

And I am always getting this exception

 
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)

...

 
 

Any clue?

Jenkins 2.222.4

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/24D68EF8-1FB4-48B6-A521-B073CFA3AA24%40cloudbees.com.
Reply | Threaded
Open this post in threaded view
|

Re: java.io.NotSerializableException: java.lang.UNIXProcess

chencho m-a
You are right. 

Adding a lot of println debug lines I have realized that the error it was not at the piece of code I have posted here but other .execute() which whose output was not being consumed and it was blocking the flow.

Thank you all for the tips.

El martes, 9 de junio de 2020, 15:00:26 (UTC+2), Devin Nusbaum escribió:
The method named `exists` from the first email is fine and does not have any problems. Adding @NonCPS to it is incorrect as explained <a href="https://www.jenkins.io/doc/book/pipeline/cps-method-mismatches/#use-of-pipeline-steps-fromnoncps" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.jenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fcps-method-mismatches%2F%23use-of-pipeline-steps-fromnoncps\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEVHI6EvamKhbjWzmAH5kA7u-wtnQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.jenkins.io%2Fdoc%2Fbook%2Fpipeline%2Fcps-method-mismatches%2F%23use-of-pipeline-steps-fromnoncps\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEVHI6EvamKhbjWzmAH5kA7u-wtnQ&#39;;return true;">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.

On Jun 8, 2020, at 18:57, Slide <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IPrMfhvABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">slid...@...> wrote:

Can you share your Jenkinsfile? There may be some contextual information that would help people help you.

On Mon, Jun 8, 2020 at 3:08 PM chencho m-a <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="IPrMfhvABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">chen...@...> wrote:
I altready tried this, with this output.

expected to call Script4.exists but wound up catching sh; see: <a href="https://jenkins.io/redirect/pipeline-cps-method-mismatches/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fredirect%2Fpipeline-cps-method-mismatches%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFam2eWuV0gHxWjeal_aQVW9-RC1g&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fjenkins.io%2Fredirect%2Fpipeline-cps-method-mismatches%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFam2eWuV0gHxWjeal_aQVW9-RC1g&#39;;return true;">https://jenkins.io/redirect/pipeline-cps-method-mismatches/

NOTE: if I use execute().text, instead of sh, it works fine.




El lunes, 8 de junio de 2020, 19:42:15 (UTC+2), Jérôme Godbout escribió:

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.

 

From: [hidden email] <[hidden email]> On Behalf Of chencho m-a
Sent: June 8, 2020 5:19 AM
To: Jenkins Users <[hidden email]>
Subject: <a href="http://java.io/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjava.io%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUUvo6vfrU_pLnxVvAv9WhMNtZFA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fjava.io%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGUUvo6vfrU_pLnxVvAv9WhMNtZFA&#39;;return true;">java.io.NotSerializableException: java.lang.UNIXProcess

 

Hi all, 

 

I have a (I hope) stupid issue that i am not able to solve

 

I am calling to a method that only call a bash script like this.

 


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}"}

}

 
 

And I am always getting this exception

 
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)

...

 
 

Any clue?

Jenkins 2.222.4

 

--
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 [hidden email].
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium=email&amp;utm_source=footer" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;"> https://groups.google.com/d/msgid/jenkinsci-users/1c647bd5-c779-427a-bf98-1a61b5074b65o%40googlegroups.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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IPrMfhvABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/ffbb95d8-8fa2-4401-8a75-5480a10fce1do%40googlegroups.com.


--
Website: <a href="http://earl-of-code.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzYece6h8IP6LUgmc96PfdL4Is8w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fearl-of-code.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzYece6h8IP6LUgmc96PfdL4Is8w&#39;;return true;">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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="IPrMfhvABAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">jenkins...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/jenkinsci-users/CAPiUgVeZYcBrJa4yzNHf76i6xg3wRyZRFTDtg65oRWLFscR5Zg%40mail.gmail.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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/08773ec8-202d-4c18-8da4-2306bc1d7b25o%40googlegroups.com.