Administration Functions

Copy Space

This script allows you to make a complete copy of an existing space.

This data will be copied:

  • Space description

  • Theme, including any custom content and style sheets

  • All content, including attachments, and comments

  • Space templates

  • Space permissions

What is not currently copied:

  • Page and comment likes.

To use, just provide space to copy from, and target key and name.

Bulk Delete Attachments

If there are many attachments to be removed, it can become very painful to remove them one by one

This script allows you to delete all the attachments (current and old versions) associated with a page (or pages).

Bulk Delete Comments from One or More Pages

Comments on pages can become irrelevant, as content changes over time, so it can be sensible to be remove them after a while, which is a tedious task to perform manually.

This script allows you to delete all comments, or all comments older than a selected number of days, for a page (or pages).

Bulk Purge Trash

This script allows you to purge all trash for:

  • One or more specific spaces

  • All spaces

Rename Labels

This script allows the renaming of labels for:

  • One or more specific spaces

  • All spaces

Specify the spaces containing labels that require renaming or tick the checkbox to specify all spaces.

Specify the label name that require renaming.

Specify the new label name.

Label names are not allowed with upper case characters.

Bulk Add/Remove Labels on One or More Pages

This script allows you to add or remove labels on all pages in a page tree.

Specify one or more page trees that require updating.

Specify whether to add or remove the labels.

Specify the labels to be added or removed. Note: For multiple labels separate them with a space.

Change Content Author

This script allows you to change the author of pieces of content, such as pages, blog posts, comments and attachments using a CQL query.

The page history and the last modified author of the content will be preserved. It is only the original Created by author that will be changed.

Clicking the Expand Examples reveals more CQL examples relevant for this script.

A common example is changing all created content from one author to another:

  • The Author is the username of the user you want to change the content to

  • The CQL clause would be:

creator = username

Copy Page Tree

Allows you to copy a tree of pages to anywhere else. If you are copying to a page within the same space, you will need to tell the script how to manipulate the page titles, as titles must be unique within a space. The way you do this is with a groovy closure - three examples are provided.

A use case might be someone that is maintaining product documentation. When a new version of the product is release, they copy the entire documentation pagetree, prepend "v1.0 ".

When the next version is released, they copy the v1.0 tree, but convert v1.0 to v2.0.

Links and image links within the tree of pages you are copying will automatically be updated to reflect any new page titles. So, let’s say you have a link where:

  • "v1.0 Product Doc/Introduction" links to "v1.0 Product Doc/Getting Started"

  • in the copied tree Introduction will link to "v2.0 Product Doc/Getting Started".

To run this you require view permissions on all the pages you are copying, plus edit permission on the target root page.

Inherit Restrictions for Pages

Inherit restrictions lets you create pages inheriting the parent page restrictions. By default, newly created pages only inherit view permissions from the parent page, not edit permissions, which means users have to set it manually everytime a page is created. Inherit Restrictions overcomes this shortcoming by offering administrators the option to specify which pages or spaces that inherit page restrictions automatically.

Read more about page restrictions in the Confluence Page Restrictions documentation.
inherit restrictions

To enable space or page inherit restrictions please select the necessary checkbox for the space or the page and save the settings. Creating a new child page in the selected space(s) or page(s) will inherit both view and edit restrictions from the parent page.

Inherit restrictions considers parent page restrictions and apply the settings to the newly created pages. The feature does not apply cumulative restrictions from all the ancestors of a page.

Prior to upgrading to recent versions of Confluence, your users may often create links in pages to Confluence content by copying and pasting the URL from the browser address bar.

Although this works, you lose features such as incoming links, and if you change the title of a page, any page that linked to it will now contain broken links.

In addition, you lose the ability to change your base URL, or export the space to another instance without breaking those links.

This script will convert these links to the correct internal storage format. If any page has links that are required to be updated, a new page version will be created, allowing you to roll back if necessary.

Links with anchors are also handled correctly. However anchors are notoriously hard to use in confluence, as they also contain the page name. Needless to say, if a link with an anchor did not work correctly before running this script, it will not work after.

The preview will show you which pages and which links are going to be updated.

Your base URL must be set corrrectly for this to work, and must match the full URLs in the pages. If it does not, then they will not appear as candidates for rewriting.
Confluence now includes javascript that will automatically do this for you at the time you paste in the link - but has no effect on existing content. So if you have already upgraded to a recent version of Confluence, you should only need run this script once.

Delete Page Tree

This works around an annoying issue where if you delete a page with child pages, the child pages get moved to the top level of the space.

This script deletes (moves to trash) a page (or pages) and all its children.

Requires remove privileges to each page you are trying to remove. If you don’t have permission to one of the pages, then no pages will be removed.

Switch User

This allows you to temporarily assume the identity of another user. You can use this for example to:

  • reproduce a problem a user is telling you they are having, e.g. diagnose a permissions problem

  • merge a pull request on behalf of another user (Bitbucket)

  • Update an issue on behalf of another user (if they are unavailable) (JIRA)

To use, enter the user ID of the user you wish to become, and press Run. To return to yourself, log out, then log in again.

When this script is used, it will generate a log entry in the audit log like so:

switch user audit log
You cannot su from a user having only administrative rights to a system administrator.

XPath Search in Pages

This is an advanced script…​ it searches each pages source using the provided xpath expression. A few example expressions are given.

You might want to use this if you require a high degree of control over the presentation of your wiki pages, and you want to make sure everything is correct.

It’s much more powerful when it comes to searching for structural problems than the Confluence search, however it is much slower. Typically you will only want to run this on a single space. It takes about 1.5 seconds to search a space with 2,500 pages.

You should be reasonably familiar with the Confluence XHTML storage format, and/or be prepared to examine a page’s source with the Confluence Source Editor, in order to work out what expression you need.

Space Statistics

This script allows you to get an overview of your Confluence spaces showing data such as:

  • Number of pages

  • Number of blogs

  • Number of comments

  • Number of attachments

  • Number of likes

  • Number of labels used

  • Distinct number of users that commented

  • Creation date

  • Last updated date

To use, select one or more spaces from the dropdown list, and press Run.

space stats 1
space stats 2

Conditions

CQL Query Condition

Enter a CQL query. This is analogous to a JQL query in JIRA and simple to use if you don’t have a programming background.

A CQL query always returns content. The types of content returned by a CQL query are:

  • Pages

  • Blog posts

  • Comments

  • Attachments

The example CQL query below returns all pages in a particular space which were created by a particular user:

space = KEY AND type = page AND creator = username

More examples are given on the Expand Examples part of each script that uses CQL. To learn more about CQL and how to use it effectively see the official documentation.

Space Administration Functions

The scripts listed below are now available in the "Space Tools" section. These scripts can be used in spaces where the user has space admin permission. Some functionality has been restricted to reflect the lower permission level, but otherwise they operate the same as the original scripts above.

  • Bulk Delete Attachments

  • Bulk Delete Comments for One or More Pages

  • Bulk Purge Trash

  • Bulk Add/Remove Labels on One or More Pages

  • Copy Page Tree

  • Copy Space

  • Delete Page Tree

  • Inherit Restrictions for Pages

  • Space Statistics

To access the new space level ScriptRunner section for Confluence, simply navigate to a space where you have space level admin permissions. Click the "Space tools" cog wheel in the bottom left of the sidebar and select ScriptRunner.

Alternatively open the space directory, select the space where you have permission by clicking the relevant "i" icon and then click on ScriptRunner.

sr space tools

For how-to questions please ask on Atlassian Answers where there is a very active community. Adaptavist staff are also likely to respond there.

Ask a question about ScriptRunner for JIRA, for for Bitbucket Server, or for Confluence.