Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Take a look here on how to do a jql search. And than search for all issues and loop through the result.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, you can.
def issueKeys = ['xxx-456', 'aaa-333']
issueKeys.each{ issueKey ->
MutableIssue ...
}
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
Can you specify the repository and dependency you are using for -
IssueManager and CommentManager?
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or clone the issue as cloning does not clone the comments. Then delete the original issue.
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.
Use Python (for free) instead...
See my code snippet: https://bitbucket.org/snippets/markdebont/EbG7Xn
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much Henning.
The above script worked for me in Jira 7.9.2 with slight syntax change (-> 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) } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use the Chrome developer tools to run JavaScript to access the JIRA API. More details are available here:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a question about JIRA. You are asking about Confluence ... just create a new question so the answers will be for Confluence.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is not easy to put everything together, but with a little groovy scripting and JIRA Command Line Interface you could probably do it.
--action renderRequest --request "/secure/DeleteComment.jspa?id=108212&commentId=48026&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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.