Hello everyone,
I've installed myGroovy plugin on my Jira Data Center instance and I've been able to create awesome scripts to auto-comment issues based on specific workflow transitions.
Some of my scripts are working great, but I'm having issues when trying to set the author of a comment to an specific user used in our automations.
In my previous scripts I had successfully set the author to the Current User (When closing an issue), but now I'd like to comment on the creation of the issue, so I could not use the "Logged In" user cause it would look confusing to the reporter to create the issue and see an automated comment written by himself.
That's what I've got so far.
This one works fine, but sets the comment to the Current User:
import com.atlassian.jira.component.ComponentAccessor
final boolean dispatchEvent = true
final String commentBody = """ Hi [~${issue.reporter.name}]Comment text here."""
def author = ComponentAccessor.jiraAuthenticationContext.loggedInUser
ComponentAccessor.commentManager.create(issue, author, commentBody, dispatchEvent)
This one isn't working. The username of the user I'm trying to set as the author of the new comment is "jira_automation":
import com.atlassian.jira.component.ComponentAccessor
final boolean dispatchEvent = true
final String commentBody = """ Hi [~${issue.reporter.name}]Comment text here."""
def author = ComponentAccessor.userManager.getUserByName(jira_automation)
ComponentAccessor.commentManager.create(issue, author, commentBody, dispatchEvent)
Try surrounding the username in quotes in the call to getUserByName(); that method expects a String argument, so by not surrounding it in quotes, it is likely being treated as an undefined variable.
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.