How to remove a selection of attachments

Description

For release 3.3 and above, getAttachmentList and runFromAttachmentList actions provide a lot of flexibility to find and do actions on a set of attachments determined by various conditions. One of the primary use cases is to remove attachments. 

  1. Condition on what content contains the attachments
    1. By space - all content in a space. Use the space parameter.
    2. By page - a specific page identified by space and title or id (content id).
    3. By search conditions similar to the UI search screen - see Searching Confluence:
      1. search - search text 
      2. searchTypes - what type of content to search, it this case only page and blogpost apply
      3. space - where to restrict seach

      4. userId - restrict to a content created by a specific user
  2. Condition on the name of the attachments to be listed or acted on - regex is a regex match string on the attachment name

Steps

  1. Determine the content condition you need. If it is a search, first use getContentList to verify that the search conditions result in the right set of pages.
  2. Determine the attachment name condition.
  3. Use getAttachmentList to list the attachments found by your criteria to verify the right set of attachments are found.
  4. Use runFromAttachmentList with the same parameters and specifying a common action of removeAttachment using the appropriate replacement variables.

Example

Here is a simple example used on this site for clean-up.

Verify list of attachments
confluence --action getAttachmentList --space info --title downloads --regex ".*-SNAPSHOT.*"
Run the remove
confluence --action runFromAttachmentList --space info --title downloads --regex ".*-SNAPSHOT.*" --common '-a removeAttachment --id @pageId@ --name "@attachment@"'