How to Create a Confluence Space Using the Confluence CLI
On this page
Recipe overview
This recipe provides step-by-step instructions on how to create a Confluence space and assign appropriate permissions using the Confluence Command Line Utility (CLI) add-on. This allows a Confluence Administrator to quickly, consistently and flawlessly create new spaces when requested by your users.
It will take you approximately 5 minutes to complete this recipe.
Recipe level
Ingredients
Preparation
Install the latest downloadable Confluence CLI Client on your computer.
If you have not done so already, follow all of the CLI installation instructions for Confluence including the steps marked optional.
Open a command window you'll use to execute CLI commands.
Steps
Create Action File
Estimated Time: 2 min
In this step, you will be creating a text file that contains the CLI actions that will create a Confluence space and set appropriate permissions for it. This file will be invoked and executed in a later step.
| Example action file: CreateNewWikiSpace_actions.txt--action addSpace --space "newSpaceKey" --name "newSpaceName" --description "This is the Space Description" --action addPermissions --space "@space@" --userId "anonymous" --permissions "viewspace" --action addPermissions --space "@space@" --group "confluence-users" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,exportspace" --action addPermissions --space "@space@" --group "confluence-administrators" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions" --action addPermissions --space "@space@" --userId "joe" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions" | |
Create Confluence CLI command
Estimated Time: 2 min
In this step, you will form the command line that will invoke the Confluence CLI to execute the action file you created in the previous step. The command is shown to the right.
| Example command: confluence --action run --file CreateNewWikiSpace_actions.txt | |
Execute Confluence CLI command
Estimated Time: 1 min
In your command window, type the command from the previous step and press Enter. The command will run, showing the result of executing the actions defined in the CreateNewWikiSpace_actions.txt file you created earlier. Note that Administrator rights to the new space will automatically be given to the user whose credentials were used when running the Confluence CLI. If you go into the Space Administration screens to look at the Space Details and Permissions screens, you should see something similar to the screenshots shown to the right. That's it! With one command, you've created a Confluence space and saved yourself from having to complete many steps to do it! | Example output: Run: --action addPermissions --space "newSpaceKey" --userId "anonymous" --permissions "viewspace" [VIEWSPACE] permissions where added to space: 'newSpaceKey' for: 'anonymous'. Run: --action addPermissions --space "newSpaceKey" --group "confluence-users" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,exportspace" [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, EXPORTSPACE] permissions where added to space: 'newSpaceKey' for: 'confluence-users'. Run: --action addPermissions --space "newSpaceKey" --group "confluence-administrators" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions" [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, REMOVEMAIL, EXPORTSPACE, SETSPACEPERMISSIONS] permissions where added to space: 'newSpaceKey' for: 'confluence-administrators'. Run: --action addPermissions --space "newSpaceKey" --userId "joe" --permissions "viewspace,comment,removecomment,editspace,removepage,setpagepermissions,editblog,removeblog,createattachment,removeattachment,removemail,exportspace,setspacepermissions" [VIEWSPACE, COMMENT, REMOVECOMMENT, EDITSPACE, REMOVEPAGE, SETPAGEPERMISSIONS, EDITBLOG, REMOVEBLOG, CREATEATTACHMENT, REMOVEATTACHMENT, REMOVEMAIL, EXPORTSPACE, SETSPACEPERMISSIONS] permissions where added to space: 'newSpaceKey' for: 'joe'. Run completed successfully. 5 actions were successful from file: /usr/local/CLI/CreateNewWikiSpace_actions.txt | |
Bonus Tip
OPTIONAL Estimated Time: 2 min
You may have established one or more sets of "standard permissions" you use in your Confluence site, such as one for a personal space, one for a team space, and another for a public space open to everyone. If this is the case, you may want to use a modified version of the CreateNewWikiSpace_actions.txt file as shown on the right. In this modified version, Lines 2 through 5 are replaced with a single line (Line 2) that uses the
| Modified action file: CreateNewWikiSpace_actions.txt--action addSpace --space "newSpaceKey" --name "newSpaceName" --description "This is the Space Description" --action copyPermissions --space "modelspace" --newSpace "@space@" | |