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

Rohit Singh May 11, 2017

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

1 vote
Matthias Gaiser _K15t_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 14, 2017

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
TAGS
AUG Leaders

Atlassian Community Events