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

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"

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

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}" }

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"

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

Suggest an answer

Log in or Join to answer
Community showcase
Louis De Jaeger
Posted 4 hours ago in Off-topic

Friday fun: your best joke

Hi all Lets make this Friday fun really fun and post one (or more) of your best jokes! The joke can be about an Atlassian product, or just a really fun joke you want to share! I’m not the best j...

22 views 1 2
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot