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' )
import groovyx.net.http.RESTClient

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

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

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:
// https://docs.atlassian.com/jira/REST/latest/#idp1389824
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>"
resp.data.issues.each { 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 ${resp.data.total} issues to ${output.name}"
} catch (groovyx.net.http.HttpResponseException e) {
if (e.response.status == 400) {
// HTTP 400: Bad Request, JIRA JQL error
fail("JIRA query failed: ${e.response.data}", e)
} else {
fail("Failure HTTP status ${e.response.status}", e)
}

}

 

1 answer

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

354 views 0 6
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