Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21: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.
×Question in a subject. We're handle sensitive data in attachments and want to purge all of them after reporter will aprove that he received them. Is there an easy way to automate this process?
Download post-function plugin from here.
https://bitbucket.org/bhushan154/jira-delete-attachments-post-function/downloads#download-263211
Haven't tested it yet. Let me know if you have any issues.
Hi Bhushan Sir,
I have installed this jar on local host but not getting how it will work can you please guide me !
Regards
Sanjay Dhandare
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 Script Runner plugin and code like this in a scripted workflow postfunction.
import com.atlassian.jira.component.ComponentAccessor
def attachmentManager = ComponentAccessor.attachmentManager def attachments = attachmentManager.getAttachments(issue) attachments.each {attachment -> attachmentManager.deleteAttachment(attachment) }
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.
It has to be „->“ instead of „->“
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what is a import i need to add on this post function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.AttachmentManager
should do the trick. :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I updated/simplified the script to incorporate your comments. This was not possible on mobile yesterday.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sure dude, thank you very much
can you help my here below i dont want copy attachment but i want create a link of the origina attachment, so i want that sub-task have a attahcment of issue parent and dont copy attachment.
can you help me with this?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.config.SubTaskManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.AttachmentManager
import com.atlassian.jira.issue.attachment.Attachment;
import com.atlassian.jira.issue.IssueFactory;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
if (issue.getIssueType().getName() != "Sub-task") {
if (ComponentAccessor.getAttachmentManager() .getAttachments(issue).size() >= 1) {
for(int i = 0; i < ComponentAccessor.attachmentManager.getAttachments(issue).size(); i++) {
//__________________________________________________________________________________________________________________________________________________
Issue parentIssue = issue
def att = parentIssue.getAttachments()[i];
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
IssueFactory issueFactory = ComponentAccessor.getIssueFactory();
String subTaskId = ComponentAccessor.getConstantsManager().getAllIssueTypeObjects().find { it.getName() == "Sub-task" }.id
IssueManager issueManager = ComponentAccessor.getIssueManager();
SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
AttachmentManager attachmentManager = ComponentAccessor.getAttachmentManager()
//__Fase
MutableIssue newSubTask = issueFactory.getIssue();
newSubTask.setSummary("Sub-Task Attachment: " + (i+1));
newSubTask.setDescription("Sub-Task with an Attachment");
newSubTask.setParentObject(parentIssue);
newSubTask.setReporterId(currentUser.username);
newSubTask.setProjectObject(parentIssue.getProjectObject());
newSubTask.setIssueTypeId(subTaskId);
//__Fase
issueManager.createIssueObject(currentUser, newSubTask);
subTaskManager.createSubTaskIssueLink(parentIssue, newSubTask, currentUser);
attachmentManager.copyAttachment(att, currentUser, newSubTask.getKey().toString())
//__________________________________________________________________________________________________________________________________________________
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So you want the Sub-task to have an attachment (displayed as a normal attachment) which is only a link to the attachment of the parent issue? I don't think this is possible.
You maybe able to create links in a field (like the description) to the parent attachments, but not have these displayed as attachments.
def pathManager = ComponentAccessor.getAttachmentPathManager()
def filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, att.id.toString())
Or you have to copy the attachments from the parent issue to the Sub-task.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want the Sub-task to have an attachment (displayed as a normal attachment)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this to copy each attachment to a single sub-task.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.attachment.CreateAttachmentParamsBean
import com.atlassian.jira.util.PathUtils
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name != SUBTASK_ISSUETYPE_NAME) {
def issueFactory = ComponentAccessor.issueFactory
def constantsManager = ComponentAccessor.constantsManager
def issueManager = ComponentAccessor.issueManager
def subTaskManager = ComponentAccessor.subTaskManager
def pathManager = ComponentAccessor.attachmentPathManager
def attachmentManager = ComponentAccessor.attachmentManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def subTaskId = constantsManager.allIssueTypeObjects.find{it.name == SUBTASK_ISSUETYPE_NAME}.id
issue.attachments.eachWithIndex{att, i ->
def newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Sub-Task Attachment: " + (i + 1))
newSubTask.setDescription("Sub-Task with an Attachment")
newSubTask.setParentObject(issue)
newSubTask.setReporterId(currentUser.username)
newSubTask.setProjectObject(issue.projectObject)
newSubTask.setIssueTypeId(subTaskId)
issueManager.createIssueObject(currentUser, newSubTask)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, currentUser)
def filePath = PathUtils.joinPaths(pathManager.attachmentPath, issue.projectObject.key, issue.key, att.id.toString())
def atFile = new File(filePath)
if (atFile.exists()) {
try {
if (atFile.canRead()) {
attachmentManager.createAttachment(
(new CreateAttachmentParamsBean.Builder(
atFile,
att.filename,
att.mimetype,
att.authorObject,
newSubTask)
)
.createdTime(att.created)
.copySourceFile(true)
.build()
)
}
}
catch (SecurityException se) {
log.warn("Could not read attachment file. Not copying. (${se.message})")
}
} else {
log.warn("Attachment file does not exist where it should. Not copying.")
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it' doesn't work there isn't attahcment in sub-task
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, simplify it:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name != SUBTASK_ISSUETYPE_NAME) {
def issueFactory = ComponentAccessor.issueFactory
def constantsManager = ComponentAccessor.constantsManager
def issueManager = ComponentAccessor.issueManager
def subTaskManager = ComponentAccessor.subTaskManager
def attachmentManager = ComponentAccessor.attachmentManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def subTaskId = constantsManager.allIssueTypeObjects.find{it.name == SUBTASK_ISSUETYPE_NAME}.id
issue.attachments.eachWithIndex{att, i ->
def newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Sub-Task Attachment: " + (i + 1))
newSubTask.setDescription("Sub-Task with an Attachment")
newSubTask.setParentObject(issue)
newSubTask.setReporterId(currentUser.username)
newSubTask.setProjectObject(issue.projectObject)
newSubTask.setIssueTypeId(subTaskId)
issueManager.createIssueObject(currentUser, newSubTask)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, currentUser)
attachmentManager.copyAttachment(att, att.authorObject, newSubTask.key)
}
}
The previous script is for Jira < 7.0.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
have a last version jira, but this script make a a new file on sub-task?
i think that the solution is to after this script delete a attachment on issue and add a post function at last transaction in the sub-task where copy attachment on issue and after delete on sub-task
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, this script creates one sub-task for each attachment. Isn't this what you want? If you want to delete the attachments from the parent issue after creating the sub-task simply add
issue.attachments.each{att ->
attachmentManager.deleteAttachment(att)
}
before the last }
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, i idid but i don't know how to add sub task attchament at main issue in the attchament field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For the last transaction of the sub-task you could use
import com.atlassian.jira.component.ComponentAccessor
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name == SUBTASK_ISSUETYPE_NAME) {
def attachmentManager = ComponentAccessor.attachmentManager
issue.attachments.each{att ->
attachmentManager.copyAttachment(att, att.authorObject, issue.parentObject.key)
attachmentManager.deleteAttachment(att)
}
}
to transfer the attachments of the sub-task back to the parent issue.
Does this help?
Henning
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're welcome :-)
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 the solution is to after this script delete a attachment on issue and add a post function at last transaction in the sub-task where copy attachment on issue and after delete on sub-task
Code to create Sub-task with a single attachment:
//Code make by Henning Tietgens
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name != SUBTASK_ISSUETYPE_NAME) {
def issueFactory = ComponentAccessor.issueFactory
def constantsManager = ComponentAccessor.constantsManager
def issueManager = ComponentAccessor.issueManager
def subTaskManager = ComponentAccessor.subTaskManager
def attachmentManager = ComponentAccessor.attachmentManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def subTaskId = constantsManager.allIssueTypeObjects.find{it.name == SUBTASK_ISSUETYPE_NAME}.id
issue.attachments.eachWithIndex{att, i ->
def newSubTask = issueFactory.getIssue()
newSubTask.setSummary("Sub-Task Attachment: " + (i + 1))
newSubTask.setDescription("Sub-Task with an Attachment")
newSubTask.setParentObject(issue)
newSubTask.setReporterId(currentUser.username)
newSubTask.setProjectObject(issue.projectObject)
newSubTask.setIssueTypeId(subTaskId)
issueManager.createIssueObject(currentUser, newSubTask)
subTaskManager.createSubTaskIssueLink(issue, newSubTask, currentUser)
attachmentManager.copyAttachment(att, att.authorObject, newSubTask.key)
}
}
After Second POST-Fucntion to delete every Attachment in the main issue:
//
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.AttachmentManager
AttachmentManager attachmentManager = ComponentAccessor.attachmentManager
def attachments = attachmentManager.getAttachments(issue)
attachments.each {attachment ->;
attachmentManager.deleteAttachment(attachment)
}
And this code is for sub-task Transaction(POST_Function): this script copy Attahcment on the main after delete every attachment in this sub-task
//Code make by Henning Tietgens
import com.atlassian.jira.component.ComponentAccessor
final SUBTASK_ISSUETYPE_NAME = "Sub-task"
if (issue.issueType.name == SUBTASK_ISSUETYPE_NAME) {
def attachmentManager = ComponentAccessor.attachmentManager
issue.attachments.each{att ->
attachmentManager.copyAttachment(att, att.authorObject, issue.parentObject.key)
attachmentManager.deleteAttachment(att)
}
}
ok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I can expand my add-on https://marketplace.atlassian.com/plugins/ru.mail.jira.plugins.attachdeleter to add new post-function. I will create a issue in my bug tracker
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That will be a very nice feature to have!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Done it. https://marketplace.atlassian.com/plugins/ru.mail.jira.plugins.attachdeleter
Next version will provide options by date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi i am using smart attachment plugin
I need to delete the attachements in some categories after the invoice is been done in the title so kindly help me to write a script in the post fuction.'
For ex : i need only input file and output file from the attachment and i need to delete other files from the attachment after the transition is been done to invoice.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you need to automate then you have to write postfunction or listener to do that job
else you can delete attachments by using rest api
/rest/api/2/attachment/{id}(DELETE)
check this
https://docs.atlassian.com/jira/REST/latest/#d2e3993
free plugin is there to delete all attachements at once
https://marketplace.atlassian.com/plugins/ru.mail.jira.plugins.attachdeleter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That's an interesting plugin but still not a lot difference between manual deleting.
Maybe there is a way to check existence of attachments in Issue on transition?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try using ComponentAccessor.getAttachmentManager()
And see similar artical.
Hope this helps you
Patina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, but writing a plugin for this procedure isn't an easy way for me :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.