Confluence CLI - creating pages from templates

Using the CLI to create a standard set of pages

The CLI can be used to automate the creation of sets of pages that follow a standard format. First, template pages are created that represent the page content for the new pages. The new pages will be created from the template pages. Permissions can be added where needed and replacement text can automatically replace text on the copy. For anything more than simple cases, the recommendation is to use a bat file, groovy script, or some other scripting language to add logic. For more complex cases where the data that drives the creation or text substitution, groovy provides a simple ability to add SQL queries to the logic.

Example - creating a standard personal space

This assumes that the confluence bat file has been customized with user and password with enough authority for these operations. The following creates a personal space for a user (newUser) with user name (New User) with a few standard pages taken from templateSpace.

// Get the latest templates - copies them to local file system for later use
confluence -a getPageSource --space templateSpace --title "Home template"    --file templates\home.txt
confluence -a getPageSource --space templateSpace --title "Public template"  --file templates\public.txt"
confluence -a getPageSource --space templateSpace --title "Private template" --file templates\private.txt"

// add new personal space for user: newUser
confluence -a addSpace --userId newUser

// add pages and replace any reference to $userId and $userName in the template source with actual values
confluence -a storePage --space ~newUser --title Home                  --file templates\\home.txt    --findReplace "$userid:newUser,$userName:New User"
confluence -a storePage --space ~newUser --title Public  --parent Home --file templates\\public.txt  --findReplace "$userid:newUser,$userName:New User"
confluence -a storePage --space ~newUser --title Private --parent Home --file templates\\private.txt --findReplace "$userid:newUser,$userName:New User"

// add space permission to allow all confluence-users to view and comment
confluence -a addpermissions --space ~newUser --permissions "viewspace, comment" --group confluence-users

// add page restriction to protect private pages
confluence} -a addpermissions --space ~newUser --title Private --permissions "view, edit" --userId newUser

Extracting data from Active Directory

In some cases, you may want to create personal spaces and pages from AD (active directory) data. This is a bit more complicated, but still possible to automate. The following process can be used:

  1. Exact AD data into some simple database files - this can be done manually or can be automated using a groovy script. Attached is an example groovy script that you can use to get the idea of what can be done in your environment. It was extracted and from a more complex script we use in our environment, so just use it as a template or to get some specific techniques for your scripts. See example.groovy
  2. Create spaces or pages based on the techniques described above using a groovy script that uses the database files created in step 1. personal-space.groovy is an example of this.

Attachments

  Name Size Creator (Last Modifier) Creation Date Last Mod Date Comment  
File personal-space.groovy 6 kB Bob Swift Nov 16, 2008 Nov 16, 2008 Automate creation of personal spaces - example script
File example.groovy 19 kB Bob Swift Nov 16, 2008 Nov 16, 2008 Extract data from AD - example script

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.