Jenkins Pipeline - getting java.io.NotSerializableException with sh and curl
<p>I'm creating a jenkins pipeline which creates a Jira Ticket at some point.
Unfortunately I'm getting: <code>java.io.NotSerializableException: org.codehaus.groovy.runtime.EncodingGroovyMethods$1</code> </p>

<p>Code:</p>

<pre><code>    token = createEncodedToken()

    def curlCommand = "curl -H 'Authorization: Basic ${token}' -X POST -d \'${payload}\' -H 'Content-Type: application/json' ${jira_url} &gt; JIRA_TICKET"

    try {
        println "executing: ${curlCommand}"
        sh "${curlCommand}"
    } catch (NotSerializableException err) {
        println "${err}"
    }
</code></pre>

<p>createEncodedToken:</p>

<pre><code>def createEncodedToken() {
   def auth = "${jira_user}:${jira_password}"
   return auth.bytes.encodeBase64()
}
</code></pre>

<p>The resulting curlCommand works! I can send it in curl or in a sample pipeline. But as soon as I use it in my jira.groovy script I get the exception.</p>

<pre><code>[Pipeline] echo
executing: curl -H "Authorization: Basic MYTOKEN=" -X POST -d "{"fields":{"project":{"key":"KEY"},"summary":"Pipeline Test","description":"Creating of an issue using project keys and issue type names using the REST API","issuetype":{"name":"Story"}}}" -H "Content-Type: application/json" https://MYJIRA/rest/api/2/issue/ &gt; JIRA_TICKET
[Pipeline] sh
[plinetest] Running shell script
[Pipeline] echo
java.io.NotSerializableException: org.codehaus.groovy.runtime.EncodingGroovyMethods$1
</code></pre>

<p>The output file JIRA_TICKET is used to read the resulting issue-key.</p>

<p>Fun fact: although I get an exception, the ticket is created... but I can't read the JIRA_TICKET file.</p>

<p>I'm currently testing it in a Sandbox Pipeline:</p>

<pre><code>def jira = fileLoader.fromGit('jira.groovy', 'MYBITBUCKET-pipeline.git', 'master', 'CREDS', '')
echo "create ticket"
def payload = '{"fields":{"project":{"key":"KEY"},"summary":"Pipeline  Test","description":"Creating of an issue using project keys and issue type names using the REST API","issuetype":{"name":"Story"}}}'
jira.createTicket(payload)
</code></pre>

<p>The call is tested and works fine. Maybe the jira lib causes the problem?
I'm aware of the Serializable concept of jenkins pipeline, but I don't get what I miss.
I'm pretty clueless right now... Any help is appreciated.</p>