Hello,
I would need to read information from the issues which are the JQL query result.
Could you please advise how to do it by Groovy script?
Cheers, Georgiy
If you want to execute a JQL expression try this:
import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.IssueManager import com.atlassian.jira.user.util.UserUtil import com.atlassian.jira.web.bean.PagerFilter jqlSearch = "project = JIRA" SearchService searchService = ComponentAccessor.getComponent(SearchService.class) UserUtil userUtil = ComponentAccessor.getUserUtil() User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() IssueManager issueManager = ComponentAccessor.getIssueManager() if (!user) { user = userUtil.getUserObject('jira_bot') } List<Issue> issues = null SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch) if (parseResult.isValid()) { def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()) // Transform issues from DocumentIssueImpl to the "pure" form IssueImpl (some methods don't work with DocumentIssueImps) issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)} } else { log.error("Invalid JQL: " + jqlSearch); }
jira_bot is a user which is used, if no current user is found, e.g. if you execute this script as a service.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
// Transform issues from DocumentIssueImpl to the "pure" form IssueImpl (some methods don't work with DocumentIssueImps) issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
I would not do the above unless you really need to. This can be slow when fetching several thousands of issues. All the methods ON documentIssueImpl should work, although you might not be able to use it as a parameter in another method. But you should just fetch the MutableIssues or whatever that you need, rather than converting them all.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
you mentioned that I can execute script as the service. Could you please advise me how to set it as service?
My aim is to run script daily, write script results into some file and publish to some network drive if it's possible.
Thank you.
Regards, Georgiy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just save the script as a .groovy file and add a groovy service (https://jamieechlin.atlassian.net/wiki/display/GRV/Script+Runner#ScriptRunner-Services) wich refers to this file.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above gave me an error below:
016-11-15 10:56:55,046 WARN [common.UserScriptEndpoint]: Script console script failed: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.ComponentManager.getSearchRequestService() is applicable for argument types: () values: [] at Script15.run(Script15.groovy:17)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't see any reference to "ComponentManager" in the code above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.