Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Jira cloud - Scriptrunner - Listener - Appending issue key

AbrahamA
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.
March 27, 2023

Hello All

In the scriptrunner listener for issue created when I append $${issue.key} it is not working in put function, however if I hard code the key like XXX-152 it works

 

I am trying to update the issue.

What is the correct way to update issue in scriptrunner listener. Please let me know

 

This does not work

def issueKey = issue.key
def result = put('/rest/api/2/issue/${issue.key}') .header('Content-Type', 'application/json') .body([ fields:[ summary: newSummary ] ])

 

This works with hardcoded key


//def issueKey = 'DWS-152'
def issueKey = issue.key
logger.info("${issueKey} or ${issue.key}")
def newSummary = 'Updated by a script'


def result = put('/rest/api/2/issue/XXX-166')
.header('Content-Type', 'application/json')
.body([
fields:[
summary: newSummary
]
])
.asString()
if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}


 

Please let me know.

Abe

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Jerryton Surya
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 27, 2023

Hi @AbrahamA 

Can you try this 

def issueKey = issue.key
def newSummary = 'Updated by a script'

def result = put("/rest/api/2/issue/${issueKey}")
.header('Content-Type', 'application/json')
.body([
fields:[
summary: newSummary
]
])
.asString()

if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}

0 votes
AbrahamA
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.
March 27, 2023

If I use ${issueKey} as part of put URL here is what I get

2
2023-03-28 03:14:50.429 INFO - PUT /rest/api/2/issue/${issueKey} asString Request Duration: 14ms
2023-03-28 03:14:50.434 ERROR - java.net.URISyntaxException: Illegal character in path at index 110: https://us.argon.polaris.connect.product.adaptavist.com/proxy-service/rest/api/1/jira/proxy/rest/api/2/issue/${issueKey}
2023-03-28 03:14:50.448 ERROR - Class: com.adaptavist.sr.cloud.events.WebhookExecution, Config: null
Jerryton Surya
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 28, 2023

Okay @AbrahamA then the issue may be something else

TAGS
AUG Leaders

Atlassian Community Events