David M. Karr
David M. Karr

Reputation: 15225

Getting SerializableException in Jenkinsfile on curl call

I'm working on a pipeline script that isn't even building anything. It clones a repo and then gets some info about the repo, and also uses the BitBucket REST API to get other information about the repository.

The following is an excerpt of the Jenkinsfile:

    stageName = 'GET-COMMITS-AND-USERS'
    stage (stageName) {
        withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: params.JP_MechIdCredentials, usernameVariable: 'USERNAME', passwordVariable: 'PASSWORD']]) {
            def uniqueCommitterMap  = {}
            def format = 'yyyy-MM-dd'
            def now = new Date()
            def aWhileAgo = now - params.JP_DaysInPastToLookFor.toInteger()
            def uniqueCommitterEmails = sh(returnStdout: true, script:"git log --date=short --pretty=format:'%ce' --after='${aWhileAgo.format(format)}' --before='${now.format(format)}' | sort -u")
            now         = null
            aWhileAgo   = null
            println "uniqueCommitterEmails[${uniqueCommitterEmails}]"
            def uniqueCommitterEmailList    = uniqueCommitterEmails.split(/[ \t\n]+/)
            uniqueCommitterEmails   = null
            println "uniqueCommitterEmailList[${uniqueCommitterEmailList}] size[${uniqueCommitterEmailList.size()}]"
            for (int ctr = 0; ctr < uniqueCommitterEmailList.size(); ++ ctr) {
                println "entry[${uniqueCommitterEmailList[ctr]}]"
                println "entry[${uniqueCommitterEmailList[ctr].split('@')}]"
                uniqueCommitterMap[uniqueCommitterEmailList[ctr].split("@")[0]]    = uniqueCommitterEmailList[ctr]
            }
            println "uniqueCommitterMap[${uniqueCommitterMap}]"
            println "end of uCM."
            uniqueCommitterEmailList    = null
            def cmd = "curl -u ${USERNAME}:${PASSWORD} https://.../rest/api/1.0/projects/${params.JP_ProjectName}/repos/${params.JP_RepositoryName}/permissions/users?limit=9999"
            USERNAME    = null
            PASSWORD    = null
            println "cmd[${cmd}]"
            def usersJson   = sh(returnStdout: true, script:cmd.toString())
            println "Past curl call." // Don't get here

The following is an excerpt of the console output when I run this job with appropriate parameters:

[Pipeline] echo
end of uCM.
cmd[curl -u ****:**** https://.../rest/api/1.0/projects/.../repos/.../permissions/users?limit=9999]
[Pipeline] echo
[Pipeline] sh
[workspace] Running shell script
[Pipeline] }
[Pipeline] // withCredentials
[Pipeline] }

[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
[DOSSIER] Response Code: 201
java.io.NotSerializableException: java.io.StringWriter
    at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
    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:1777)
    at java.util.HashMap.writeObject(HashMap.java:1354)
    at sun.reflect.GeneratedMethodAccessor28.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)

As you can see, it appears to execute the "sh" step to call "curl" for the BitBucket REST API, but it doesn't get past that. I can't figure out what object it's complaining about.

Update:

I'm running Jenkins 2.19.2.

The pipeline has the following settings:

Upvotes: 2

Views: 2419

Answers (2)

Steven
Steven

Reputation: 11

I came across the same issue, but it seems that the issue is not caused by sh at all. It is probably caused by a variable you've defined above the sh step, which is not Serializable.

Upvotes: 1

cringe
cringe

Reputation: 13950

To answer your question I ran Jenkins v2.32.2 from the official Dockerfile and created the following test pipeline:

node() {
    stage('serialize') {
        def USERNAME = 'myusername'
        def PASSWORD = 'mypassword'
        def cmd = "echo curl -u ${USERNAME}:${PASSWORD} https://.../${params.TEST_PARAM1}/permissions/users?limit=9999"
        USERNAME    = null
        PASSWORD    = null
        println "cmd[${cmd}]"
        def usersJson   = sh(returnStdout: true, script:cmd)
        println "Past curl call."
    }
}

I also added a text parameter to the build job to have something similar than your params.JP_ProjectName variables.

And this is my output when running with the text parameter set to "defaultValue modified":

Started by user admin
[Pipeline] node
Running on master in /var/jenkins_home/workspace/42217046
[Pipeline] {
[Pipeline] stage
[Pipeline] { (serialize)
[Pipeline] echo
cmd[echo curl -u myusername:mypassword https://.../defaultValue modified/permissions/users?limit=9999]
[Pipeline] sh
[42217046] Running shell script
+ echo curl -u myusername:mypassword https://.../defaultValue modified/permissions/users?limit=9999
[Pipeline] echo
Past curl call.
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS

As you can see, the pipeline finished successully. And I can see no issue with the pipeline.

Maybe you can update your question with a screenshot of your job configuration and the version number of your jenkins installation.

Upvotes: 1

Related Questions