Scriptrunner - Parse comment with regex and send custom mail to recipients in comment

AB March 23, 2021

Hi,

unfortunately, I have not yet found a suitable answer, so I ask my question directly here:

- Once a comment is created, the comment content should be parsed to users mentioned as @mention.
- If a @mention is found, it should be checked if the user belongs to a certain project role or not.
- If the condition is met (@mention belongs to role), a mail should be sent to this user.

I thought that the rubric "Listener" would fit to this, but you can only store fixed mail addresses there.

What is the best way to proceed?

Thanks!

1 answer

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2021

Actually, no, you don't have to rely on the fixed email address using the "Send a custom email" script listener.

You can use the "Condition and Configuration" script to set your recipients.

In that script, there is a "mail" variable in the binding.

So you can parse the comment there and then set mail.setTo("your recipients")

Note that when parsing your comment, you'll want to look for [~userName] not @DisplayName since the body of the comment is the underlying wiki format.

Another possibility to explore is to use a "Custom Listener" which allows you to Listen to the "MentionIssueComment" which has a built-in "toUsers()" method that contains the list of users mentioned in the comment.

But that means you would have to code your own interactions with the jira mail systems.

So 2 approaches:

  1. Code your own parsing and leverage the built-in scrirptrunner mail creation
  2. Use the built-in parsing and code your own mail sending

Suggest an answer

Log in or Sign up to answer