Hello,
Have a post function which gets a custom field containing email addresses separated by semicolons. Able to parse them and ideally wanted to do a POST to create users.
Only the first user gets created, then it errors out
Here is the code:
//Parse Emails
def users = customFieldManager.getCustomFieldObject("customfield_10100")
def userlist = issue.getCustomFieldValue(users).toString()
String[] emails = userlist.split(";")
String out = ""
//Iterate Emails and Create Users via REST
for(String email in emails){out += email.split("@)[0]
def http3 = new HTTPBuilder("http://localhost:8080/rest/api/2/user")
http3.request(POST, ContentType.JSON){
requestContentType = ContentType.JSON
request.addHeader("Authorization: Basic YWRtaW46YWRtaW4=", "ContentType: application/json")
body = [
name: email,
password:"password",
emailAddress: email,
displayName: email.split("@)[0],
applicationKeys:"jira-core"
]
response.success = { resp, JSON -> return JSON }
response.failure = { resp, JSON -> return JSON }
}
}
Here is the error I'm getting:
2018-05-07 14:07:21,000 http-nio-8080-exec-10 ERROR admin 847x502x2 1xxytla 172.17.0.1 /secure/CommentAssignIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: PROYEC-1, actionId: 91, file: <inline script>
groovyx.net.http.HttpResponseException:
at groovyx.net.http.HTTPBuilder.defaultFailureHandler(HTTPBuilder.java:651)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:503)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:434)
at groovyx.net.http.HTTPBuilder.request(HTTPBuilder.java:383)
at groovyx.net.http.HTTPBuilder$request.call(Unknown Source)
at Script4.run(Script4.groovy:24)
Wondering if there's some sort of pause I should do, as logs show the first user gets created, the POST is made but there's something making subsequent calls fail...