I'm creating a jenkins pipeline which creates a Jira Ticket at some point. Unfortunately I'm getting: java.io.NotSerializableException: org.codehaus.groovy.runtime.EncodingGroovyMethods$1
Code:
token = createEncodedToken() def curlCommand = "curl -H 'Authorization: Basic ${token}' -X POST -d \'${payload}\' -H 'Content-Type: application/json' ${jira_url} > JIRA_TICKET" try { println "executing: ${curlCommand}" sh "${curlCommand}" } catch (NotSerializableException err) { println "${err}" } createEncodedToken:
def createEncodedToken() { def auth = "${jira_user}:${jira_password}" return auth.bytes.encodeBase64() } 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.
[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/ > JIRA_TICKET [Pipeline] sh [plinetest] Running shell script [Pipeline] echo java.io.NotSerializableException: org.codehaus.groovy.runtime.EncodingGroovyMethods$1 The output file JIRA_TICKET is used to read the resulting issue-key.
Fun fact: although I get an exception, the ticket is created... but I can't read the JIRA_TICKET file.
I'm currently testing it in a Sandbox Pipeline:
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) 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.
createEncodedToken()? I bet it causes the issue.