How do I get custom field values in a JIRA issue to pass into a Groovy script

I'm trying to get a value from a created issue in JIRA and pass it into a post-function script using Script-Runner plugin but I don't know what the call methods are. From researching, I found this:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager

def componentManager = ComponentManager.instance
def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
def customFieldManager = componentManager.getCustomFieldManager()

def cf = customFieldManager.getCustomFieldObjectByName("Lab Equipment")
def fieldConfig = cf.getRelevantConfig(issue)

def process = "/isis/scripts/scripts/myscript.sh $fieldConfig".execute()

Lab Equipment is a string in a drop-down list.

My ultimate goal is to retrieve values from the custom fields in JIRA and send it to a bash script as arguments. It just doesn't work.

I would just like simple commands that pulls the values I need from any custom field so I can use it later.

1 answer

1 accepted

2 votes

You don't want this line:

def fieldConfig = cf.getRelevantConfig(issue)

You want something like:

def labEq = issue.getCustomFieldValue(cf)

Then labEq should contain the value of the field (actually it will contain an Option object, but if you use it in a String context it will be toString'd). If not:

use labEq?.value

to get the value. No IDE in front of me so double-check stuff.

Thanks. That worked perfectly.

I was able to call the value with $labEq in the script. Thanks.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,760 views 11 18
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