You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Perform a JQL Search in ScriptRunner for Jira

Overview

Use this snippet to look for issues based on a JQL search. This code can be used as part of a larger bulk-administration or workflow automation task, in the Script Console and other features.

Example

The available issue resolutions in a project have been updated, leaving several issues with incorrect resolution values. I want to locate all issues with the incorrect value, so I can perform a bulk action to update them all. To save me time manually searching, I can use this script to run a JQL search, locating all affected issues.

Requirements

  • Jira Jira (8.0 - 8.14)
  • ScriptRunner for Jira ScriptRunner for Jira
    
import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.search.SearchException import com.atlassian.jira.web.bean.PagerFilter import org.apache.log4j.Level // Set log level to INFO log.setLevel(Level.INFO) // The JQL query you want to search with final jqlSearch = "Some JQL query" // Some components def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser def searchService = ComponentAccessor.getComponentOfType(SearchService) // Parse the query def parseResult = searchService.parseQuery(user, jqlSearch) if (!parseResult.valid) { log.error('Invalid query') return null } try { // Perform the query to get the issues def results = searchService.search(user, parseResult.query, PagerFilter.unlimitedFilter) def issues = results.results issues.each { log.info(it.key) } issues*.key } catch (SearchException e) { e.printStackTrace() null }
Discovered an issue? Report it here

Suggested for you