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

How to list all projects in Script Runner?

Mitchell Lau October 29, 2019

Objective: Release a projects' version using Jira Cloud Script Runner (groovy). Ideally, when a ticket is transitioned to a certain workflow status, the script runner will release the version associated with the ticket. 

Problem: How do I list all the software projects? 

I've searched the documentation looking for a way to get all projects + the versions that are included  in the project to no avail. It seems unirest isn't able to import projects like it would import a trigger issue.

I have considered calling: 

HttpResponse<JsonNode> response = Unirest.get("/rest/api/2/project/{projectkey}/versions")
.basicAuth("example@example.com", "<api_token>")
.header("Accept", "application/json")
.asJson();

 and adding a static project key to find my versions.

Any other, more efficient ideas?

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2019

Hi Mitch,

Thank you for your question.

I just wanted to share that we have an example script on how to copy the versions between projects located in the documentation page here.

I can confirm that the rest call in the versions variable shows the syntax for a rest call that can return all versions for a project and that this may be useful as a reference guide for an alternative way to achieve your requirement to what has been posted above.

Regards,

Kristian

Mitchell Lau October 31, 2019

Hey Kristian,

Does the documentation you sent apply to Script Listeners on Jira Cloud ? Static checking is throwing an error..Here's my snippet:

def versions = Unirest.get("http://example.atlassian.net/rest/api/2/project/${projectName}/versions")
.basicAuth("user@example.com", "[redacted]")
.header("Accept", "application/json")
.asObject(List).body

//logger.info ("${response}")

versions.each {
boolean releasedValue = it.released
boolean userReleaseValue = it.userReleaseDate

 Error for the releaseValue:

No such property: released for class: java.lang.Object
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 1, 2019

HI Mitchell,

 

The snippet I shared was froo the Script Console and may need to be modified for a Script Listener to get any properties you require depending on what events you configure the listiner to run for. 

Thanks,

Kristian

0 votes
Mitchell Lau October 30, 2019

This can be closed.

Iago Docando
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.
July 8, 2020

Hello, Mitchell. In your message from Oct 31. you're exposing your user and password for the world to see. You may want to remove that ;)

TAGS
AUG Leaders

Atlassian Community Events