How to Fetch the Issues with the Component Field using JIRA REST API in groovy?

I am trying to write the groovy script using JIRA REST API and trying to Fetch the issue with Summary,Release Notes,module .I am able to do but not fully like not able to Fetch the release Notes and module Name in the html file.

In addition Currently I am trying to Fetch it with FixVersion Field and want to do it with Component Field but I am also not able to do it as well.

Below is my script

I want to Fetch all issues which is having value for e.g. "ABCD 1.2 R" in component Field instead of FixVersion 

I want to include release Notes and  Module name.SO we have such values in Componenet Field

Component: M ban, M wba, M san, M workbook, R PX 3.8U1 (Active), R PX 3.8U2 (Future), T Ba

Need to search with R PX 3.8U1 and then get all issues with module name which is in component field for e.g : ban,wba,workbook in release notes file against that issue.

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )

final String USAGE =
"Usage: -Djira.username=xxx -Djira.password=xxx -Djira.fixVersion=1.0"

String jiraUsername = 'ABCD'
String jiraPassword = '**********!'
String jiraFixVersion = 'N'

println "Getting issues..."
if (!jiraUsername?.trim()) {
fail("Empty property: jira.username " + USAGE)

if (!jiraPassword?.trim()) {
fail("Empty property: jira.password " + USAGE)

if (!jiraFixVersion?.trim()) {
fail("Empty property: jira.fixVersion " + USAGE)

final String JIRA_SEARCH_URL = "https://yourjirainstance/rest/api/latest/"
// see JIRA docs about search:
String JQL = "project = NCTX"
JQL += " AND issuetype in standardIssueTypes()"
JQL += " AND status in (Resolved, Closed)"
JQL += " AND fixVersion = \"${jiraFixVersion}\""

def jira = new RESTClient(JIRA_SEARCH_URL)

def query = [:]
query['os_username'] = jiraUsername
query['os_password'] = jiraPassword
query['jql'] = JQL
query['startAt'] = 0
query['maxResults'] = 1000

try {
def resp = jira.get(path: "search",
contentType: "application/json",
query: query)
resp.status == 200
def output = new File('issues.html')
output << "<html><body><ul>" { issue ->
def url = "https://yourjirainstance/browse/${issue.key}"
output << "<li><a href=\"$url\">${issue.key}</a>: ${issue.fields.summary}</li>"
output << "</ul></body></html>"
println "Exported ${} issues to ${}"
} catch ( e) {
if (e.response.status == 400) {
// HTTP 400: Bad Request, JIRA JQL error
fail("JIRA query failed: ${}", e)
} else {
fail("Failure HTTP status ${e.response.status}", e)



1 answer

This widget could not be displayed.

In order to get more fields in the search response, you can use the fields parameter of the search endpoint and list all the fields you want to return, e.g. fields=summary,fixVersion in order to return these two fields, see also the docs for this.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

481 views 3 17
Read article

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