2

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.

5
  • May be this link can help you: support.cloudbees.com/hc/en-us/articles/… Commented Sep 2, 2016 at 16:00
  • It doesn't :( I moved the curl execution to a separate method and annotated it with @NonCPS. Still the same error. Commented Sep 2, 2016 at 16:19
  • What is the code inside createEncodedToken()? I bet it causes the issue. Commented Sep 3, 2016 at 20:19
  • Added the createEncodedToken code Commented Sep 5, 2016 at 7:51
  • Did you solve it? Commented Jul 7, 2017 at 10:19

2 Answers 2

3

encodeBase64() does not return a string. It returns a class which implements groovy.lang.Writeable, which has a toString() method.

You need to call toString() explicitly.

Sign up to request clarification or add additional context in comments.

Comments

0

Please try to use new URL(jira_url).openConnection(); instead of curl. You can refer to this Groovy built-in REST/HTTP client?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.