Forums

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

Scriptrunner for Jira Cloud - FixVersion and Auto-transition

venkat2305
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 30, 2018

Hello,

I need assistance with Scriptrunner for Jira cloud. In the past, I have done Scriptrunner customization on Jira Server but never used the cloud version. I am looking into the REST API documentation, but would appreciate some help to kick start and get the hang for how it works.

This is what I am trying to do -

As part of "Deployment" Issue, "Deployed" status Post-transition, I want to get the associated FixVersion field value. Then, want to get the list of all Agile Issues that are linked to the same FixVersion. For each of those Agile Issues, I want to auto-transition those that are in "Development Completed" status to "Ready for Testing" status and ignore the rest.

 

Thanks in advance.

 

Venkat

 

2 answers

1 accepted

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Champion
August 1, 2018

Hi Venkat,

Thank you for your question.

I can confirm that the way that Jira Cloud works is different to Jira server as there is only a rest API for the cloud version and no Java API as described in the documentation here

In order to achieve this requirement you would need to create a script which performs a JQL search in order to identify all issues which macthed the specified fix version, and then for each of those issues to loop over each issue returned and only transition the ones which match a specified issue type and status. 

I have created an example of a script which can be ran on the script console inside of ScripRunner for Jira cloud to show how this can be done which is located here.

You will be able to use this script in order to show how you could create a similar script as a post function or a listiner to transition the required issues.

Please not that when executing a transition a script will only be able to transition the issue   if the transition to the required status from the current status exists inside of the workflow.

If this issue has solved your requirement can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Venkat Krishnamoorthy August 1, 2018

Hi Kristian,

Thanks a lot for your time. Your script is very clean and precise and gives a nice structure that I can follow in my future scripts.

Earlier today, I came up with a working script (combination of documentation and other Atlassian answers :)) that is pretty close to yours. This is working as Post-Function script on the "Deployment" Issue type.

def issueKey = issue.key
String fixV = get("/rest/api/2/issue/${issueKey}").asObject(Map).body['fields']['fixVersions']['name']
def fixVer = fixV.replaceAll("\\[|\\]","")

Map<String, Object> searchResult = get('/rest/api/2/search')
.queryString('jql', "fixVersion = ${fixVer} AND project = XYZ AND issuetype != 'Deployment Request' AND status = 'Development Completed'")
.queryString('fields', 'project')
.asObject(Map)
.body

def issues = (List<Map<String, Object>>) searchResult.issues

for(issue in issues)
{
def res = post("/rest/api/2/issue/" + issue["key"] + "/transitions")
.header("Content-Type", "application/json")
.body([
"transition": [
"id": "51"
]
])
.asString()
}

Like Matt Noe likes this
0 votes
Kristian Walker _Adaptavist_
Community Champion
August 1, 2018

Hi Venkat,

Thankyou for confirming that you managed to create a working solution. 

Could you please mark the answer as accepted so that other users searching for searching a similar question can see that this script contains a correct answer which they can use.

Regards,

Kristian

Venkat Krishnamoorthy August 1, 2018

Kristian,

For some reason, I dont see the "Accept Solution" check mark. Please see attached.

 

VenkatNo Accept check mark.jpg

Kristian Walker _Adaptavist_
Community Champion
August 1, 2018

Hi Ventak,

Normally it would be directly below the answer but I cannot see what options below the answer form your screenshot. 

Kristian

Nic Brough -Adaptavist-
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.
August 1, 2018

Should be even more to the left of that blue up-arrow than everything else on the screen.

Screen Shot 2018-08-01 at 16.04.02.png

Venkat Krishnamoorthy August 1, 2018

In the past, when I was using different Atlassian account, I have accepted answers. It must be something to do with my current account. I dont see the check mark at all (Please see screenshot attached). This is my first post using this account.

Nic, do you mind accepting Kristian's answer?

 

Thanks.

No checkmark to accept.jpg

Suggest an answer

Log in or Sign up to answer