Hi
App - Scriptrunner for Jira
Function - Custom scheduled Job (cronjob)
Usercase - Run a JQL query, retrieve the results and send email to all assignee of tickets
The below code does get me the usernames from my jql filter, but i need the email address to use.
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
import com.atlassian.jira.mail.Email
import com.atlassian.jira.mail.settings.MailSettings
import com.atlassian.mail.MailException
import org.apache.log4j.Logger
// Set log level to INFO
log.setLevel(Level.INFO)
// The JQL query you want to search with
final jqlSearch = "project = SDPTS AND summary ~ test"
// Some components
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def searchService = ComponentAccessor.getComponentOfType(SearchService)
// Parse the query
def parseResult = searchService.parseQuery(user, jqlSearch)
if (!parseResult.isValid()) {
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*.assignee
} catch (SearchException e) {
e.printStackTrace()
null
}
Thanks
Rich
If you can't get this working in ScriptRunner, you may want to try our app which is built to support this UX from the ground up: https://marketplace.atlassian.com/apps/1211069/notification-assistant-for-jira-email
Thanks Boris, Ill check it out. I was able to simplify the requirement and create a job to send mail to a Jira group, this may be an acceptable workaround.
Rich
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.