How to find Confluence pages and then do something
On this page
Description
The CLI provides a number of advanced capabilities to enable actions without scripting. For Confluence, that usually revolves around finding content. This will discuss various techniques that can be used. In many cases, not only do you want to find content, but, you want to do something specific with the content that is found. Like modify it (see also How to automate adding text to Confluence pages) or do something with labels or permissions. The various run actions make this easy to do without scripting.
Links
Search
This search is based on Confluence's search index and is the fastest way to search for simple text similar to goggle searching. It is roughly the same as the search available on the UI for finding text strings. This is the recommended technique for most searches and is supported on getPageList, runFromPageList, getContentList, and runFromContentList.
Parameter | Default | Description | Values |
---|---|---|---|
cql | The most powerful search available from Confluence - see Advanced Searching With CQL | valid cql statement |
Find Pages Via Metadata
This means using things like title, page hierarchy, labels, and similar. Use getPageList and runFromPageList actions.
Parameter | Default | Description | Values |
---|---|---|---|
space | All spaces | Restrict to a single space if specified. Required unless labels is not blank. | space key, @all |
labels | All pages | Restrict to pages with at least one label. | comma separated list of labels |
title | All pages | Subset to related pages based on other parameters | |
ancestors | off | Set to add all ancestors of the page identified by the title parameter | Set using --ancestors |
descendents | off | Set to add all descendents of the page identified by the title parameter | Set using --descendents |
children | off | Set to add all (direct) children of the page identified by the title parameter | Set using --children |
regex | Regex pattern for matching titles. If title matches regex and other conditions, it will be included |
Search Content
This means actual source (storage format) content of the page which is different than normal index based search normally done on content using CQL. Normally only used for finding text in source that normally would not be in the search index.This is the most accurate way to find specific content on pages, but it is very resource intensive as it must retrieve page source from the server to do the regex pattern matching. This can take minutes to hours depending on the number of pages that need to be searched. Use with caution. If performance is a major issue, there is another, more advanced approach - see How to use SQL to find pages.
Parameter | Default | Description | Values |
---|---|---|---|
regex2 | Regex pattern for matching storage format content. If page content matches regex and other conditions, it will be included |
Example
Finding specific content
confluence --action getPageList --space DEMO --regex2 ".*find this exact content on a page.*"
Legacy Search
Legacy search parameters like search, searchModified, searchTypes, and related have been deprecated for some time and have been removed for version 7.0 in favor of Confluence CQL which is significantly more powerful. See Version 7.0 - Removed Actions and Parameters for more details.
Doing Something
If you need to act on the pages found, the easiest way is to use runFromPageList or runFromContentList to automatically run an action or script of actions for each page found. Things like modifyPage or removePage.
Example
confluence --action runFromPage --space DEMO --regex2 ".*find this exact content on a page.*" --common "--action removePage --id @pageId@"
For more examples, go to How to Globally Search and Modify Content.