Hello
I would like to create a script with ScriptRunner, that will send the jira issue direct URL to the assignee email or to a specific email address/
Thanks
Hi, @Asaf Yosovich. I found this 'Solved' question from another community member that I think may contain an example you can work with.
Check out the answer from Ivan Tovbin
Use Scriptrunner to send one email collating all issues assigned to user
Good luck,
-dave
To construct an URL in a groovy script, it's helpful to fetch the "BaseUrl" property for your instance.
This way you don't have to hard-code the URL and the script will work even if you migrate to a different environment.
import com.atlassian.jira.component.ComponentAccessordef baseUrl = ComponentAccessor.applicationProperties.jiraBaseUrl
Depending on the context where you want this script to execute, I'm assuming you'll already have access to the "issue" object.
So you can construct the URL for the link back to the issue:
def issueUrl = baseUrl + '/browse/' + issue.key
To send an email, I generally use the SingleMailQueItem object and MailQueue component.
Something like this:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.mail.Emailimport com.atlassian.mail.MailExceptionimport com.atlassian.mail.MailFactoryimport com.atlassian.mail.queue.SingleMailQueueItemimport com.atlassian.mail.server.MailServerManagerimport com.atlassian.mail.server.SMTPMailServerMailServerManager mailServerManager = ComponentAccessor.mailServerManagerSMTPMailServer mailServer = mailServerManager.defaultSMTPMailServerIssue issue //assumes this is already provided by the script contextdef baseUrl = ComponentAccessor.applicationProperties.jiraBaseUrldef issueUrl = baseUrl + '/browse/' + issue.keyif (mailServer && !MailFactory.settings.sendingDisabled) { Email email = new Email('recipientEmail') email.from = mailServer.defaultFrom email.subject = 'you email subject' email.mimeType = "text/html" email.body = """your email body including the <a href="$issueUrl">link to the issue</a>""" try { SingleMailQueueItem item = new SingleMailQueueItem(email) ComponentAccessor.mailQueue.addItem(item) log.info "Success: email has been added to the mail queue" } catch (MailException e) { log.error "Failed to send an email due to error: e.message" }} else { log.warn "Cannot send email. Outgoing emails are currently disabled"}
It looks like you're new here. Sign in or register to get started.