Skip to end of banner
Go to start of banner

How to automate adding text to Confluence pages

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

Description

This describes how to add some standard text to the beginning or end of a bunch of Confluence pages. This assumes you have access to the Confluence database for running a read only query to select the pages that you are interested in updating. 

Error rendering macro 'jira' : Unable to locate Jira server for this macro. It may be due to Application Link configuration.
 will provide an improvement to this soon.

Test carefully

Test on a few pages first to make sure the result is what you want!

Steps using version 2.6.0 or above

  1. Construct a SQL query that selects the pages you are interested in. Test against your database.

    select '--id ' || contentid from content where content.title like '%title 1%' and contenttype = 'PAGE' and content.spaceid = (select spaceid from spaces where spacekey = 'zconfluencecli2')
    
  2. Figure out the runFromSql parameters for accessing your database.

  3. Put it all together in a single command: 

    confluence -a runFromSql --common "-a modifyPage --content \"before existing content\" " --database confluence-3.5.13 --driver postgresql --sql "select '--id ' || contentid from content where content.title like '%title 1%' and contenttype = 'PAGE' and content.spaceid = (select spaceid from spaces where spacekey = 'zconfluencecli2')"
    

Use find and replace support to modify existing content

--findReplace and/or --findReplaceRegex can be used to modify the contents with or without adding additional content. Watch out for unintended substitutions - choose your find string/regex carefully.

Example
--action modifyPage --id 12345678 --findReplace "xxx:yyy"

 

 

Alternatives

runFromPageList and runFromList or similar can also be used to accomplish similar things without SQL.

 

Steps before version 2.6.0

  1. Create a text file appendPage.txt similar to the following: 

    Example
    -a getPageSource --space @space@ --title "@title@" --file temp-page-source.txt
    -a storePage --space @space@ --title "@title@" --file temp-page-source.txt --content "Stuff to add before current page. \n " --content2 " \n Stuff to add after current page."
    

    The page content on storePage is determined by content (if provided), followed by file content (if provided), followed by content2 (if provided).

     

  2. Construct a SQL query that selects the pages you are interested in. Test against your database.

    select '--findReplace \"@title@:''' || content.title || ''',@space@:' || spaces.spacekey || '\"' from content, spaces where content.title like '%title 1%' and content.spaceid = spaces.spaceid"
    
  3. Figure out the runFromSql parameters for accessing your database.

  4. Put it all together in a single command: 

    confluence -a runFromSql --common "-a run --file appendPage.txt" --database confluence-3.5.13 --driver postgresql --sql "select '--findReplace \"@title@:''' || content.title || ''',@space@:' || spaces.spacekey || '\"' from content, spaces where content.title like '%title 1%' and content.spaceid = spaces.spaceid"
    

Trouble with titles

Titles that contain quotes (single or double) will mess this up. Use --continue on the runFromSql action to keep going even if there are errors and then handle those cases separately.

  • No labels