Prepping for JIRA 6.4 yanking the Jelly rug out from under us. Moving all our jelly service auto-transition jobs to groovy. Got a solution that works most of the time...except...
On the validateTransition I sometime get the [You do not have the permission to comment on this issue.] response in projects/issue-types where neither the workflow start and end status have conditions to prevent commenting, which is common practice for some projects that don't want closed tickets to have activity. Even still, I understand there's an outstanding feature/bug where the standard post-functions transition before applying the comment. I get that. But even in the code block labeled "My Hack Attempt" where I try to insert an inputParam object with no comment (yes, tried null inputParam it throws error) it still returns [You do not have the permission to comment on this issue.]
Snippet:
IssueInputParameters inputParams = issueService.newIssueInputParameters() inputParams.setComment(commentBody) IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(jiraBot.getDirectoryUser(), issue.getId(), transitionId, inputParams) ErrorCollection errorCollection = transitionValidationResult.getErrorCollection() if (errorCollection.hasAnyErrors()) { //OFTEN GET THE [You do not have the permission to comment on this issue.] }
My Hack Attempt..
for (Issue issue in issues) { if(transitionId > 0) { log.warn "IssueID ${issue.key} being transitioned." projectName = issue.getProjectObject().getName() commentBody = buildComment(stdComment.get(filterId), projectName) log.debug "CommentBody: " + commentBody IssueInputParameters inputParams = issueService.newIssueInputParameters() inputParams.setComment(commentBody) IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(jiraBot.getDirectoryUser(), issue.getId(), transitionId, inputParams) ErrorCollection errorCollection = transitionValidationResult.getErrorCollection() if (errorCollection.hasAnyErrors()) { log.warn "Possible transition error: " + errorCollection.getErrorMessages() + " - Retrying..." //KLUDGE ALERT! - BUG IN ATLASSIAN TRANSITION SERVICE ENFORCES VALIDATIONS BASED ON TARGET STATUS, NOT CURRENT STATUS //THIS WILL REJECT A VALID COMMENT AS PART OF A TRANSITION INPUT PARM, SO WE DO THEM SEPARATELY IN THIS CASE if(errorCollection.getErrorMessages().toString().contains("[You do not have the permission to comment on this issue.]")){ MutableIssue mutableIssue = issueManager.getIssueObject(issue.getId()) //do the comment thing first. thanks fo nuthin! commentManager.create(mutableIssue, jiraBot, stdComment.get(filterId), true) //reset input params to nothing inputParams = issueService.newIssueInputParameters() //revalidate transitionValidationResult = issueService.validateTransition(jiraBot.getDirectoryUser(), issue.getId(), transitionId, inputParams) if (errorCollection.hasAnyErrors()) { log.warn "Still didn't work for ${issue.key}. See error below:" log.error errorCollection.getErrorMessages() }else { log.warn "No transitions errors this time! Transitioning ${issue.key}." IssueService.IssueResult issueResult = issueService.transition(jiraBot.getDirectoryUser(), transitionValidationResult) log.info "Transition result: ${issueResult} " } } } else { log.warn "No transitions errors. Transitioning ${issue.key}." IssueService.IssueResult issueResult = issueService.transition(jiraBot.getDirectoryUser(), transitionValidationResult) log.info "Transition result: ${issueResult} " } }else{ log.warn "No transition id. Commenting only for ${issue.key}." //transitionID is zero then we can assume its comment-only (no transition desired) commentManager.create(issue, jiraBot, stdComment.get(filterId), true) } } ImportUtils.setIndexIssues(wasIndexing);
Full BitBucket of my solution is here for anyone needing help/examples!
Community moderators have prevented the ability to post new answers.
For anyone who has to replace Jelly-based auto-transition scripts and runs into this problem:
Our extensive testing has identified at least the conditions that cause the "You do not have permission to comment on this issue." error. And it is an error, at least a completely unfriendly, misleading message.
So, create "admin only" transitions (ugh) - that is "hidden" transition with condition=sys-admin and then run this code in your service as a sys-admin that comments the issue only if the transition is successful:
IssueInputParameters inputParams = issueService.newIssueInputParameters() // Doesn't work. Have to set comment separately after successful transition below // inputParams.setComment(commentBody) inputParams.setResolutionId(RESOLVE_TIMEOUT) IssueService.TransitionValidationResult transitionValidationResult = issueService.validateTransition(jiraBot, issue.getId(), transitionId, inputParams) ErrorCollection errorCollection = transitionValidationResult.getErrorCollection() if (errorCollection.hasAnyErrors()) { log.error "AUTO-RESOLVE ERROR: Transition: " + transitionId + " for issue ${issue.key}. Error Message Next Line." log.error errorCollection.getErrorMessages() }else { log.info "AUTO-RESOLVE SUCCESS: Transitioning ${issue.key}." IssueService.IssueResult issueResult = issueService.transition(jiraBot, transitionValidationResult) log.info "Transition result: ${issueResult} " //You're here so transition was successful. Now make a comment. Ugh. //must make a mutable version of the issue for the comment manager MutableIssue mutableIssue = issueManager.getIssueObject(issue.getId()) //make the comment log.debug "Making comment for issue: ${issue.key} " commentManager.create(mutableIssue, jiraBot, commentBody, true) }
Yes, it sends two emails. Take it up with JIRA's API dev team.
Hey Jamie - did you find a workaround? I've got auto-transition script that will just leave an accumulation of tickets un-transitioned. I can close them if I don't comment but that's unfriendly. I'm desperate enough to consider custom templates/events but this would mean dozens of "admin" transitions across multiple workflows to be added. Thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@HomeAway I know this is a years late response but in case this helps someone else with this problem, when I was working thru a P2 plugin I ran into something similar. I had to first assign the issue to lets say your full control admin, jirabot, once the user was overlaid on the issue then you should be able to add a comment to said issue, or even transition the issue as needed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think that's a jira bug: https://jira.atlassian.com/browse/JRA-23814 . I've had the same issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, definitely. jirabot is full admin. And the logic that makes a comment first and then tries an "empty" (no comment) transition, leaves the comment on the issue. Strange.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you tried to add a comment as jiraBot? Does that user definitely have permission to add a comment?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the documented issue with commenting I mentioned above: https://jira.atlassian.com/browse/JRA-40997 But as I said, the workflows throwing the validation error do not have jira.permission.comment.user=false.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.