Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Start CURL from scriptrunner

Tomasz Bryła
Contributor
December 10, 2018

Hi,
I try to resolve problem with Invalid Worklogs in Tempo after moving issue to another project. I wrote my own script based on this, but not work properly. I use My Groovy addon and I use CURL to serach and update date in Jira by REST API. My script find properly information in Jira, but I have problem with update a account filed. It’s look like curl2 isn’t execute. Can you take a look on my script and tell my where is a problem? I have another script listener where i execute curl command many time in one script and it’s work good. My Jira is install on Windows Server.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.issue.util.IssueChangeHolder;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
import groovy.json.JsonSlurper
def JIRA_API_URL = (“https://myjira.eu/rest/api/latest/issue/”)
def user_password = “user:password”
def accountCf = “customfield_11110”
def commentManager = ComponentAccessor.commentManager
def cfm = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByKey(“user”)
def issue= event.getIssue()
def projId = issue.getProjectId().toString()
def issueKey = issue.getKey().toString()
def curl = “E:/curl/bin/curl.exe -u user:password https://myjira.eu/rest/tempo-accounts/1/account/project/${projId}”
def output = curl.execute().text
def slurper = new groovy.json.JsonSlurper()
def results = slurper.parseText(output)
def id = results.id.toString()

def accountId = id.substring(1, id.length() – 1)
def sout = new StringBuilder(), serr = new StringBuilder()
def query = ‘{“””fields”””:{“””‘+accountCf+'”””:”””‘+accountId+'”””}}’
def curl2 = [ ‘E:/curl/bin/curl.exe’,(” -u “+user_password+” -X PUT –data “+query+” -H “+'”Content-Type:application/json”‘+” “+ JIRA_API_URL+issueKey)].execute()
curl2.consumeProcessOutput(sout, serr)
def error = curl2.waitFor();
def texto = sout.toString();
def texto2 = serr.toString();
log.debug(texto + “::” + texto2)
issue.store()

 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Anton Chemlev - Toolstrek -
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 12, 2018

Hi,

What do you get as a result of running script? Error?

TAGS
AUG Leaders

Atlassian Community Events