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

Calling REST Api from within script-runner post-function (and needed libraries)

Bryan Karsh
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.
June 6, 2013

I couldn't edit my original question to be more clear, so I am rewording it as a new question.

I am experimenting with script runner in a post function in one of my projects. I want to get a dump of all fields of theissue , which I can then pass to an external too for some processing.

I know I can do something like this:

def curl = "/usr/bin/curl -u foo:bar http://jira.example.com:8080/jira/rest/api/latest/issue/BLAH-100.json"

def output = curl.execute().text

This does give me a variable ($output) containing populated fields for the issue that I can plug into a bash script I have on the server for parsing, etc.

However, I am trying to see if I can do something similar from straight within groovy, without a call to some external tool.

Any advice? I am a groovy noob, so if you have any examples, please let me know. I have some examples online, but they seem to call libraries that I don't have (guessing they were written for stand alone groovy, and not script runner..?)

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Bryan Karsh
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.
September 29, 2013
0 votes
Rama Krishna July 28, 2015

Can any one show how to send post request with data to JIRA to update or insert issue from Java client.

0 votes
GabrielleJ
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 4, 2014

do you have any idea why this is not working with -X PUT? GET is working fine...

def curl = "/usr/bin/curl -u FECRU_CREDENTIALS -H Content-Type:application/json -H Accept:application/json -X PUT -d FECRU_DATA FECRU_REST_API"

0 votes
Bryan Karsh
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.
June 10, 2013

There is probably a better way to go about this, but I ended up doing the folowing to get system and custom field data:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;

 
// gets a reference to the IssueManager and CustomFieldManager manager classes
IssueManager issueManager = ComponentManager.getInstance().getIssueManager();
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager();
 
// gets a reference to the desired issue and custom field
Issue issue = issueManager.getIssueObject( "FOOBAR-100" );


def cflist = customFieldManager.getCustomFieldObjects(issue);

def map = new HashMap<String,String>()

cflist.each {cf ->
Object value = issue.getCustomFieldValue(cf)
    map << [(cf):"$value"]

}

def systemfields = issueManager.getIssue ("FOOBAR-100")  //getting GenericObject since it seems to contain issue fields

map << systemfields   // left-shift systemfields map into map to create consolidated map



 
//Example showing line by line output:
map.each{ k, v -> println "${k}::${v}" }

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events