Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Bulk-Delete Comments

Hi,

we had a buggy Jelly-Script which postet ten-thousands of comments on some issues.

Deleting them manually is not possible, every reload of the issue takes a few minutes.

The last chance i see is deleting them by a direct database-delete-statement.

Did anyone delete comments like this before or does anyone know if there are dependencies? or has anyone a jelly-script which is able to delete comments through api?

thanks & regards

12 answers

1 accepted

11 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 24, 2013 • edited Mar 10, 2021

Deleting directly from the database is not recommended. But you can use the Script Runner plugin and the following script to delete all comments containing a specific text (in this case "Bla Bla Bla") in a specific issue (here TXS-561).

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 = 'TXS-561'

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('Bla Bla Bla')) {
        commentManager.delete(comment)
    }
}

Henning

 

Just wanted to say this worked like a charm for a comment spam issue I had. Thanks!

Thx for your script... I have many issue with the same comment and I will delete this comment. How can I include alle issue keys in this script?I will bulk delete this Comment?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2014

Take a look here on how to do a jql search. And than search for all issues and loop through the result.

Ok, but I can't include the issue keys in your script? for example

String issueKey = 'xxx-685'; String issueKey = 'xxx-686' etc...

or with another separator?

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 19, 2014

Yes, you can.

def issueKeys = ['xxx-456', 'aaa-333']

issueKeys.each{ issueKey ->

MutableIssue ...

}

THX... it works fine :-)

Thanks alot for this post @Henning Tietgens. This saved me a lot of work when cleaning-up the comments some spambot left on our JIRA instance over the weekend. I also took the time to write a quick How-To to apply your script to the JIRA instance: http://www.luke1410.de/blog/?p=29

Like Sameer.Khazi likes this

Hi @Henning Tietgens. I am on JIRA cloud and this script is giving me [x] errors to the left of all the imports at the top of your code before I even run it. The errors state "unable to resolve class com.atlassian.jira...(issue or component)" at each line (1-5). Am I missing something between the date of this post and now (a few years)?

Thanks!

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Sep 01, 2017 • edited

Hi Daniel,

this is a restriction of JIRA Cloud plugins. See ScriptRunner package import restrictions

On JIRA Cloud the plugin (and therefore your script) is not able to directly interact with the JIRA system (see Script Runner Migration Guide for details), instead the REST API has to be used.

It should be possible to use https://docs.atlassian.com/jira/REST/cloud/#api/2/issue/{issueIdOrKey}/comment to accomplish the same thing as my script above, but I don't have a script ready for you.

Henning

Hi Henning,

Can you specify the repository and dependency you are using for -

IssueManager and CommentManager?

Thanks

Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Mar 10, 2021

Hi,

In fact there are no special dependencies. If you open the Script Runner console, you can paste this code (containing less imports than the old one above):

import com.atlassian.jira.component.ComponentAccessor

String issueKey = 'TXS-561'

def issueManager = ComponentAccessor.issueManager
def commentManager = ComponentAccessor.commentManager

def issue = issueManager.getIssueObject(issueKey)
def comments = commentManager.getComments(issue)
comments.each {comment ->
if (comment.body.contains('Bla Bla Bla')) {
commentManager.delete(comment)
}
}

Best,
Henning 

1 vote
Cyril Egan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 24, 2013

Or clone the issue as cloning does not clone the comments. Then delete the original issue.

the change history gets lost...

Use Python (for free) instead...

See my code snippet: https://bitbucket.org/snippets/markdebont/EbG7Xn

Thank you so much Henning.

The above script worked for me in Jira 7.9.2 with slight syntax change (-&gt; replated with ->)

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 = 'TXS-561'

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('Bla Bla Bla')) {
        commentManager.delete(comment)
    }
}

For anyone that this might help!

https://github.com/CJ-Edwards-QHR/bulk-delete-comments-jira/blob/master/groovy

(cant seem to post codeblocks?)

This is my naive approach to remove bulk/bad comments from across multiple issues in a project. It is not fast if you are searching a large project that is full of comments!!

This was based on code found at https://gist.github.com/lhotari/caafb4d394412f491861 which did not work for me at all.

I created a python script to remove all comments for a specific Jira issue. 
It uses the API from Jira. Found it the easiest way without a plugin.

Here you go:
https://bitbucket.org/snippets/fty4/aeG4Bb/delete-all-jira-comments-from-issue

You can use the Chrome developer tools to run JavaScript to access the JIRA API. More details are available here:

http://stackoverflow.com/a/37950118/2266979

0 votes
Steffen Stamprath
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Apr 08, 2015

This is for Confluence.. not for Jira.. ;)

Like Mark de Bont likes this

I wrote a Jira Script Runner plugin Groovy script to delete Jira comment spam entered by a spambot that uses a username "Patrickmorton". See https://gist.github.com/lhotari/caafb4d394412f491861for the source.

As a simple administrator, without access to scripts etc, how do I delete all comments from a page?

I've already copied page to retain snapshot with current comments.

Confluence 5.3

Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 24, 2014

This is a question about JIRA. You are asking about Confluence ... just create a new question so the answers will be for Confluence.

Like Mark de Bont likes this
0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 25, 2013

It is not easy to put everything together, but with a little groovy scripting and JIRA Command Line Interface you could probably do it.

  1. getIssueList with JQL to find the issues affected - produces a CSV that has the issue's numeric id
  2. getCommentList for each issue affected - produces a CSV of comments that has the comment's numeric id
  3. renderRequest to delete the comment similar to this example
--action renderRequest --request "/secure/DeleteComment.jspa?id=108212&amp;commentId=48026&amp;Delete=Delete"

An easier alternative is available if you are really good at SQL against the JIRA database (and NOT OnDemand) to construct the right renderRequest (like above) for all the comments you need to remove. Then just use runFromSql to run all of them.

Hi Bob. Huge fan, get your Friday emails, have a few of your plugins. I think I'm fairly good at SQL, I'm both our Oracle DBA and SQL Server DBA (jira is on MS-SQL) , and our Atlassian admin, but I haven't studied the Jira data model enough to know the tables or where clause. My case is very easy. We have a programmer that is basically 'pinging' SFDC, if he get's a success there, he writes a comment to a specific Jira issue, i.e., 'SFDCtest-123', but he wants me to do a cleanup of those comments every so often.

Do you know the SQL to delete all comments from a specific Jira issue id? delete * from whatever where jirakey = 'SFDCtest-123'?  I can try to reverse engineer, but what the heck, thought I might ask. 

-Tom McCallum

Nevermind. I'm good. Thanks. 

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jul 24, 2013

Your options are very limited here. To avoid loss of history and data, you're basically down to two options

- What Henning said - even the Jira CLI and Jelly can't delete the comments, the script runner pretty much is the only approach

- As you said, hack the database. You will need to stop Jira, get a backup, remove lines from "jiraaction table", start Jira and then update the affected issues index (either with a global index, or a bulk edit or comment on the ones you've changed).

I've had a similar problem in the past, and it is moderately safe as long as you do NOTHING else. But I never recommend database hacking, because it's so easy to get it wrong.

Suggest an answer

Log in or Sign up to answer