Excerpt |
---|
|
Using the CLI to create a standard set of pages |
Description
Situations arise where it would be nice to be able to create a new space pre-populated with pages or to create a new section of an existing space with a standard set of pages. This could be for new projects as they get defined, new design pages, new customers, or new employees' user spaces. Processes or company policies may demand specific permissions and standards.
...
Tip |
---|
|
We use template as a generic term (not related to Confluence templates). Here a template page is just a normal page that can be edited in the standard way, but is used as the base for a copy. |
Info |
---|
title | Download Server or OnDemandCloud |
---|
|
This works with Confluence Download Server or OnDemandCloud. |
Tip |
---|
|
For Confluence Download Server users, a self service setup is possible using CCLI - see How to create pages from template pages - self service |
Example - creating a standard personal space
The following creates a personal space for a user (userId) who has a manager (managerId). We assume the template pages are already defined in a space with key: templateSpace. We use replacement variables of the form @xxxx@ so the script can be generalized. See the findReplace paramater used below.
...
No Format |
---|
|
# add personal space
--action addSpace --userId "@userId@"
# add admin permission for the user to their own space
--action addpermissions --space "~@userId@" --permissions "SETSPACEPERMISSIONS" --userId @userId@
# add space permissions to allow general user access to personal space
--action addPermissions --space "~@userId@" --group confluence-users --permissions "VIEWSPACE, COMMENT"
# add space permissions to all manager more access
--action addPermissions --space "~@userId@" --userId @managerId@ --permissions "VIEWSPACE, EDITSPACE, EXPORTPAGE, SETPAGEPERMISSIONS, REMOVEPAGE, COMMENT, REMOVECOMMENT, CREATEATTACHMENT, REMOVEATTACHMENT, EXPORTSPACE"
# add pages by copying template pages
--action copyPage --space templateSpace --title @home --newSpace "~@userId@" --descendents --replace --noConvert
--action copyPage --space templateSpace --title "Public stuff" --newSpace "~@userId@" --descendents --parent @home --replace --noConvert
--action copyPage --space templateSpace --title "Private stuff" --newSpace "~@userId@" --descendents --parent @home --replace --noConvert
--action copyPage --space templateSpace --title "Manager stuff" --newSpace "~@userId@" --descendents --parent @home --replace --noConvert
# add page permission to protect private section
--action addPermissions --space "~@userId@" --title "Private stuff" --permissions "view, edit" --userId @userId@
# add page permission to protect manager section
--action addPermissions --space "~@userId@" --title "Manager stuff" --permissions "view" --userId @userId@
--action addPermissions --space "~@userId@" --title "Manager stuff" --permissions "view, edit" --userId @managerId@ |
Run the action script
No Format |
---|
|
confluence --action run --file personal-space.txt --continue --findReplace "@userId@:bob,@managerId@tom" |
Tip |
---|
|
We use --continue so that all actions will be run even if there are errors on one or more actions. This allows for the script to be corrected and re-run easily. |
Example output
No Format |
---|
|
Run: --action addSpace --userId bob
Space added with key: ~bob name: bob and url: http://imac2.local:8118/display/~bob
# add admin permission for the user to their own space
Run: --action addpermissions --space "~bob" --permissions "SETSPACEPERMISSIONS" --userId bob
[SETSPACEPERMISSIONS] permissions where added to space: '~bob' for: 'bob'.
# add space permissions to allow general user access to personal space
Run: --action addPermissions --space "~bob" --group confluence-users --permissions "VIEWSPACE, COMMENT"
[VIEWSPACE, COMMENT] permissions where added to space: '~bob' for: 'confluence-users'.
# add space permissions to all manager more access
Run: --action addPermissions --space "~bob" --userId tom --permissions "VIEWSPACE, EDITSPACE, EXPORTPAGE, SETPAGEPERMISSIONS, REMOVEPAGE, COMMENT, REMOVECOMMENT, CREATEATTACHMENT, REMOVEATTACHMENT, EXPORTSPACE"
[VIEWSPACE, EDITSPACE, EXPORTPAGE, SETPAGEPERMISSIONS, REMOVEPAGE, COMMENT, REMOVECOMMENT, CREATEATTACHMENT, REMOVEATTACHMENT, EXPORTSPACE] permissions where added to space: '~bob' for: 'tom'.
# add pages by copying template pages
Run: --action copyPage --space templateSpace --title @home --newSpace "~bob" --replace --noConvert
Page 'Home' copied to: 'Home' in space ~bob. Page has id: 94833027
Run: --action copyPage --space templateSpace --title "Public stuff" --newSpace "~bob" --parent @home --replace --noConvert
Page 'Public stuff' copied to: 'Public stuff' in space ~bob as child of '@home'. Page has id: 94833032
Run: --action copyPage --space templateSpace --title "Private stuff" --newSpace "~bob" --parent @home --replace --noConvert
Page 'Private stuff' copied to: 'Private stuff' in space ~bob as child of '@home'. Page has id: 94833033
Run: --action copyPage --space templateSpace --title "Manager stuff" --newSpace "~bob" --parent @home --replace --noConvert
Page 'Manager stuff' copied to: 'Manager stuff' in space ~bob as child of '@home'. Page has id: 94833034
# add page permission to protect private section
Run: --action addPermissions --space "~bob" --title "Private stuff" --permissions "view, edit" --userId bob
[View, Edit] permissions where added to page: 'Private stuff' in space: '~bob' for: 'bob'.
# add page permission to protect manager section
Run: --action addPermissions --space "~bob" --title "Manager stuff" --permissions "view" --userId bob
[View] permissions where added to page: 'Manager stuff' in space: '~bob' for: 'bob'.
Run: --action addPermissions --space "~bob" --title "Manager stuff" --permissions "view, edit" --userId tom
[View, Edit] permissions where added to page: 'Manager stuff' in space: '~bob' for: 'tom'.
Run completed successfully. 11 actions were successful |