Hi, I'm running a JQL using Escalation service (Scriptrunner), for the below code; having issues in resolving warning. any help !!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.label.LabelManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.ComponentManager
ComponentAccessor.commentManager.create(issue, "jira_admins","Hello [~${issueUser}], Please check the status of the RCA.", true)
Error: (though the comment gets added. still warning is thrown)
at com.onresolve.scriptrunner.jobs.JiraIdentitySwitchingService.switchIndentityAndExecute(JiraIdentitySwitchingService.groovy:27) at com.onresolve.scriptrunner.jobs.IdentitySwitchingService$switchIndentityAndExecute.call(Unknown Source) at com.onresolve.scriptrunner.canned.jira.jobs.EscalationService$_execute_closure2.doCall(EscalationService.groovy:129) <<<<some deleted data>>>>> at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalStateException: There is no ID mapped for the user key 'JIRA_Admins' at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySetForUserKey(DefaultUserPropertyManager.java:32) at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySet(DefaultUserPropertyManager.java:25) at com.atlassian.jira.user.preferences.DefaultUserPreferencesManager.getExtendedPreferences(DefaultUserPreferencesManager.java:22) at com.atlassian.jira.bc.issue.watcher.AutoWatchService.isAutoWatchEnabledForUser(AutoWatchService.java:56) at com.atlassian.jira.bc.issue.watcher.AutoWatchService.onIssueEvent(AutoWatchService.java:43) at sun.reflect.GeneratedMethodAccessor2245.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.event.internal.SingleParameterMethodListenerInvoker.invoke(SingleParameterMethodListenerInvoker.java:40) ... 405 more
IssueUser is working fine; taking the current issue assignee else reporter.
I tried with below, but no comment was posted; it took the wrong user.
issueInputParameters.setComment('Added comment')
Also, History shows that I've added all labels again; is there way to add comment (only 1) by a particular user only. ie. to replace the loggedinuser code below with ex/ jira_admins user key.
LabelManager labelManager = ComponentAccessor.getComponent(LabelManager.class)
labelManager.addLabel(ComponentAccessor.jiraAuthenticationContext.getLoggedInUser(), issue.id, "RCA_AUTO", false)
I think the fundamental issue you are seeing is with the selection of the user field in the escalation service configuration, not in the code. Try to re-select the user you want the job to run as.
Regarding your labels question, where is this used? Can you elaborate, your question is confusing? You are asking about labels, but say you want to add comment. Is this about labels or comment?
You can use ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(applicationUser) to change the currently logged in user for the context of the script.
Hi Peter,
The Job is to have a add to label and comment too
Can you provide the way it required to code for ComponentAccessor.jiraAuthenticationContext.setLoggedInUser(applicationUser)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you set up the user correctly in the Job configuration, you don't need to use setLoggedInUser, scriptrunner will take care of that for you
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Peter,
I'm updating the sub-task of the tickets too.
For the subtask I'm performing below: at the line below that's adding the comment to the ticket with the user I've stated below; but the error log still makes 300 lines+ making difficult to trace the logger I've added.
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
hasSubTask = true
subTasks.each {
if ((it.getStatus().getName() == "In Progress") || (it.getStatus().getName() == "Open")){ // || (it.getStatus().getName() == "Blocked")) {
hasSubTaskOpen = true
currentCMUser = it.assignee ? it.assigneeId : it.reporterId
commentBody = "Hello [~${currentCMUser}], Please update the status of Sub-Task. Please move it to Blocked, incase it will be done in upcoming sprint."
ComponentAccessor.commentManager.create(it, "JIRA_Admins", commentBody, true) //Comment on the ticket
log1.info(it.key)
getIssueUserEmail = it.assignee ? it.assignee.emailAddress : it.reporter.emailAddress
currentCMUserF = null
if(getUserIDfromSlack(getIssueUserEmail) != null)
notificationToSlackFunc(it, getUserIDfromSlack(getIssueUserEmail), "Task") //Comment via Slack to user
currentCMUserF = null
}
Log error:
Caused by: java.lang.IllegalStateException: There is no ID mapped for the user key 'JIRA_Admins' at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySetForUserKey(DefaultUserPropertyManager.java:32) at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySet(DefaultUserPropertyManager.java:25) at com.atlassian.jira.user.preferences.DefaultUserPreferencesManager.getExtendedPreferences(DefaultUserPreferencesManager.java:22) at com.atlassian.jira.bc.issue.watcher.AutoWatchService.isAutoWatchEnabledForUser(AutoWatchService.java:56)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Perhaps the issue is as simple as Jira not finding the correct user for "JIRA_Admins".
The method where the author is specified as string is deprecated anyway.
Try to fetch that user using userManager
def adminUser = Componentaccessor.userManager.getUserByName('jira_admins')
or use the jiraAuthentication Context (as specified in your escalation)
def adminUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
then use that to create the comment:
ComponentAccessor.commentManager.create(it, adminUser, commentBody, true)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Peter, post my question - I used below that worked.
def adminUser = ComponentAccessor.jiraAuthenticationContext.loggedInUse
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.