Bulk Delete Comments from (Self-Hosted) JIRA Issues



Published: 2018-09-20 22:28:06 +0000
Categories: Misc,

Language

Misc

Description

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

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)
    }
}

Requires

Keywords

JIRA, Delete, Bulk, Comments,

Latest Posts


Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion