How to remove pages with no specific labels using Confluence CLI
This article explains how to remove pages that do not have specific labels using Confluence Command Line Interface (CLI).
Instructions
Use runFromPageList to run actions for each page from a list of pages and use removePage to remove pages that do not have specific labels based on CQL.
For this example, consider a sample space with pages and labels added to them; where pages, page5 and page6, have labels, label2 and label3, respectively. Here, the pages page5 and page6 that do not have the label label1,are removed from the space.
Ensure that the CLI client file is updated with the required information.
Run the following CLI action to remove the pages that do not have the specified label (in this example, label1):
--action runFromPageList --cql "space = 'JSON' and label not in ('label1')" --common "-a removePage --id @pageId@"
In this example, the output of the CLI action is:
Run: -a removePage --id 30310402 Removed page 'page5' in space JSON. Run: -a removePage --id 30310404 Removed page 'page6' in space JSON. Run completed successfully. 2 actions were successful
page5 and page6 pages are now deleted from the given space as shown:
The parameters used with the above action are:
- --cql value refers to CQL content search.
- --id value refers to numeric ID of an item like a page.
It is recommended to test the command in a non-production environment or run the action with the --simulate parameter to verify the behaviour before deploying.