Bulk Delete Comments from (Self-Hosted) JIRA Issues (Misc)
The following snippet can be passed into JIRA's Groovy Script/ScriptRunner plugin in order to locate comments within a given issue and bulk delete them
Once complete, it's wise to update the indexes within the administration area
Details
- Language: Misc
Snippet
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
String issueKey = '[[ISSUE KEY]]'
IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager
MutableIssue issue = issueManager.getIssueObject(issueKey)
List<Comment> comments = commentManager.getComments(issue)
comments.each {comment ->
if (comment.body.contains('[[SEARCH TEXT]]')) {
commentManager.delete(comment)
}
}
Usage Example
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
String issueKey = 'ISS-30'
IssueManager issueManager = ComponentAccessor.issueManager
CommentManager commentManager = ComponentAccessor.commentManager
MutableIssue issue = issueManager.getIssueObject(issueKey)
List<Comment> comments = commentManager.getComments(issue)
comments.each {comment ->
if (comment.body.contains('Me Too')) {
commentManager.delete(comment)
}
}