sshagent seems to cause serialization failure

38 views
Skip to first unread message

David Karr

unread,
Dec 12, 2016, 7:08:02 PM12/12/16
to Jenkins Users
In a Jenkinsfile, I'm trying to scp a zip file to a remote host, and ssh some commands to unpack it when it gets there.

I managed to add a "SSH username with private key" credential, and I can see it in the "Credentials" list.  I'm referencing that uuid in my "sshagent" block.

When I run the job, I see the following:
JP_MechIdPrivateKey[<myusername>-private-key] class[java.lang.String]
[ssh-agent] Using credentials <myusername>
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Java/JNR ssh-agent
[ssh-agent] Skipped registering BouncyCastle, not running on a remote agent
[ssh-agent] Started.
[Pipeline] {

[Pipeline] sh
[ssh-agent] Stopped.
[usl-parent] Running shell script
[Pipeline] }
[Pipeline] // sshagent
[Pipeline] }
[Pipeline] // dir
[Pipeline] sh
...
java
.io.NotSerializableException: sun.nio.fs.UnixPath
    at org
.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    at org
.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
...
Caused by: an exception which occurred:
   
in field locals
   
in field caller
   
in field e
   
in field program
   
in field thread
   
in field body
   
in field step
   
in field thread
   
in field this$0
   
in field returnAddress
   
in field parent
   
in field caller
   
in field parent
   
in field parent
   
in field parent
   
in field parent
   
in field capture
   
in field def
   
in field closures
   
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup@d12af23
Finished: FAILURE

The code in question looks like this:
                    println "JP_MechIdPrivateKey[${JP_MechIdPrivateKey}] class[${JP_MechIdPrivateKey.class.name}]"
                    sshagent
(credentials: [JP_MechIdPrivateKey]) {
                        sh
"scp ${javadocJarPath} ${JP_JavadocJarHost}:/tmp"
                        sh
"ssh ${JP_JavadocJarHost} \"cd ${JP_JavadocRootRemotePath}; rm -rf ${versionNumber}; mkdir ${versionNumber}\""
                        sh
"ssh ${JP_JavadocJarHost} \"cd ${JP_JavadocRootRemotePath}; jar xvf /tmp/${baseFileName}\""
                   
}

I believe I've heard that in order to avoid serialization issues, I have to put things in @NonCPS methods, but I don't understand what parts of this would need to go into a @NonCPS method, and what CANNOT go into a @NonCPS method.

David Karr

unread,
Dec 12, 2016, 7:26:48 PM12/12/16
to Jenkins Users
Oh, and I tried running this with the "sshagent" block commented out, and the exception does not occur (and nothing useful gets done, of course), so it's definitely coming from that, even though the stacktrace doesn't give me any hint of where it's happening in the script.
Reply all
Reply to author
Forward
0 new messages