Automate Removal of Unwanted Attachments in JSM Cloud Requests

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Cloud - This article applies to Atlassian products on the cloud platform.

Warning

This article uses Automation to delete attachments based on a regex. Please adjust the regex to suit your use case scenario and test it in your sandbox environment before using it in production. Deleted attachments can't be recovered.

Summary

Learn how to efficiently remove unnecessary attachments from Jira Service Management requests using automation on the cloud platform.

Keep your email threads clean by removing signature images

Email signatures often include images, such as company logos or social media icons. An email thread may have images/ logos from multiple responders' email signatures. In these cases, many attachments can build up via an email exchange, making the "real" issue content hard to see, as this unnecessary content is also included in comments after email processing. 

Click the 'Delete' icon in the attachment section, confirm the deletion, and repeat for each attachment.  This action doesn't remove comment references, which will display Preview Unavailable.

Hide email signatures

We introduced a feature that hides email signatures in the issue view using an expandable component: Hide email signatures from the issue view and portals. For some email clients, the default signature detection may not work as expected if the signature contains multiple images. As a result, these images are added as attachments after email processing.

Here are some open Feature requests to provide this functionality and one of them is already in Review by our Product Managers: 

Scope of the workaround

Attention! Proficiency in regex, webhooks, and APIs is strongly advised for optimal results from this workaround.

This workaround works with the combinations of Webhooks and Automation, and its scope is:

  1. Remove unwanted attachments based on a criteria (name to be defined and adapted to your business needs).
  2. Remove references to those attachments from the Issue Description (on Issue Creation).
  3. Remove references to those attachments from the Comments (on both scenarios).
  4. Not generate additional Customer notifications.

How are unwanted attachments identified?

Identify the pattern in the name of the most common signature images attached to your issues. For the sake of this article, we are considering that the files we want to remove  match with this regex:

^image0\w*.+(jpg|png)$


This will match filenames that:

  • Start with  " image0 ".
  • Followed by  0  or  more alphanumeric chars.
  • Followed by  any kind of characters.
  • Ending with  jpg or png.

Edit the regex based on your use case, the regex needs to follow the syntax described below. Here are some resources you can refer to: 

Setup

The workaround involves covering 2 scenarios :

  • Remove attachments added during issue creation.
  • Remove attachments added when new comments are added.

Scenario 1: Remove attachments added during issue creation

Please note that the KB involves an action to delete the last comment added on the issue as soon as the issue is created since these comments refer to the attachments added during issue creation.

  • If other automations add comments when an issue is created, those comments might be deleted. In that case, you can either choose a different trigger for the other rules or avoid using this action.
  • If you skip this action, and your signature attachments are also comments, the comments will show Preview Unavailable because the attachments are deleted.. 


  • You can import the following rule Automation-Rule-removeAttachments-NewIssues_2023-05-17T14_49_00.478Z.json 
    • Reference article on how to import the above rule to your site - Import and export Jira automation rules/
      The rule is in a disabled state so that it doesn't run automatically before making the necessary changes are made to the regex that suits your needs and the necessary testing is done. Next, It's important to select the right Project Scope after importing the new rule. Also, leave the  Import rule owners unchecked. 

  • Or Create it based on the following video:


  • Or Create an automation rule with the following configuration:
    • Add trigger Field value changed  to monitor changes made to the Attachment field on issue create the action.
    • Add an Advanced branching component to do certain actions on each attachment added using the smart value {{attachment.filename}} accessed with a variable name file within the branch.
    • Within the branch add an Advanced compare condition to match the file name against the regular expression based on your requirement. (warning) For the scope of this kb, we are using the same expression as discussed above. If the file name matches our regular expression then add the Delete attachments action to delete the current file. 
    • Outside the branch, add the component Delete comment to delete the last comment added as part of the issue creation that is referring to the attachment.
    •  Next, if these attachments are referred to in the Description field, add the Edit issue action for the Description field to replace any references to the signature file names, for this kb we are replacing references for imageXX: 

      {{issue.description.replaceAll("[\s|.]*(!image0\w.*[jpg|png]\|thumbnail!)","")}}

Scenario 2: New comments added including attachments

This scenario has the below requirements: 

  • Trigger a Jira webhook when an attachment is added to a specific project. This will be used for new comments including attachments.
  • Automation to delete signature attachments - Configure an automation rule that will listen for the webhook events for attachments and remove the attachments that match the signature regex.
  • Automation to remove attachment references from comments.

Automation to delete signature attachments

  • You can import the following rule  Automation-Rule-removeAttachments-NewComments_2023-05-17T14_12_00.217Z.json
    • (warning) After importing the rule, it's necessary to Regenerate the Webhook URL. This is done from the Trigger
    • Reference article on how to import the above rule to your site - Import and export Jira automation rules
      (info) The rule is in a disabled state so that it doesn't run automatically before making the necessary changes are made to the regex that suits your needs and the necessary testing is done. Next, It's important to select the right Project Scope after importing the new rule. Also, leave the  Import rule owners unchecked. 

  • Or, Create it based on the following video: 


  • Or Create an automation rule with the following configuration:
    • Add an Incoming webhook  trigger.
    • Next, add the Create variable action to store the value of smartvalue {{webhookData.attachment.filename}} in the variable file.
    • Compare if the filename matches the signature regex. (warning) For the scope of this kb, we are using the same expression as discussed above. If the file name matches the regular expression then add the Delete attachments action to delete the file added.

      ^image0\w*.+(jpg|png)$
  • Here is what the rule will look like:

Automation to remove attachment references from comments

  • You can import the following rule Automation-Rule-removeAttachmentsReferences4NewComments_2023-05-17T14_23_57.873Z.json
    • Reference article on how to import the above rule to your site - Import and export Jira automation rules
      (info) The rule is in a disabled state so that it doesn't run automatically before making the necessary changes are made to the regex that suits your needs and the necessary testing is done. Next, It's important to select the right Project Scope after importing the new rule. Also, leave the  Import rule owners unchecked. 

  • Or Create it based on the following video: 
  • Or, Create an automation rule with the following configuration:
    • Add trigger Issue commented for all comments.
    • Next, add a condition to check if the comment refers to any attachment using the below regex. (warning) For the scope of this kb, we are using the same expression as discussed above.

      [\s|.]*(!image0\w.*[jpg|png]\|thumbnail!)
    • If the condition matches the Edit comment action to replace any references to the signature file names in the last comment. For this kb we are replacing references for imageXX: 

      {{issue.comments.last.body.replaceAll("[\s|.]*(!image0\w.*[jpg|png]\|thumbnail!)","")}}

Trigger Jira webhook when an attachment is added

Finally, configure a Jira webhook to be triggered when an attachment is created.

  • Copy the webhook URL you have obtained from the first automation rule in this scenario
  • Go to System >  Webhooks > Create a webhook. Paste the URL and add the following variables at the end of the URL to detect the issue key .

    ?issue=${issue.key}
  • Add some JQL to limit the scope of the webhook to desired project and select the  Attachment created event. 
Last modified on May 5, 2025

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.