Sometimes you might want to create a confluence page corresponding to an issue. For instance when new Epic types are created, or when high-priority issues change state.

The simplest example of this is shown here:

The outline of this script is essentially:

Assuming you have set up the app link to authenticate with OAuth or Trusted Apps, it will create the page as the user running the transition (so make sure they have the correct permissions in Confluence).

Whilst it’s perfectly possible to create the page remotely without an app link, it will require embedding credentials for the Confluence administrator account in your script, which is not desirable.

The most important part of this is setting up the parameters to be passed to the REST API:

def params = [
    type: "page",
    title: pageTitle,
    space: [
        key: "TEST" // set the space key - or calculate it from the project or something
    // if you want to specify create the page under another, do it like this:
    // ancestors: [
    //     [
    //         type: "page",
    //         id: "14123220",
    //     ]
    // ],
    body: [
        storage: [
            value: pageBody,
            representation: "storage"

Most of this is self-explanatory. You can hard-code the key or you might want to set it dynamically based on the project, issue type etc etc.

If you do not specify an ancestor page your page will be created at the root of the space, which might not be under the home page, and hence not easy to find.

The final part is where you set the body of the page (using Confluence Storage Format syntax).

Here is a full example of using the storage format to create the page:

The interesting part:

// write storage format using an XML builder
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro' ('ac:name': "jira") {
    'ac:parameter' ('ac:name': "key", issue.key)

// add more paragraphs etc
xml.p ("Some additional info here.")

We use a builder to make sure the XML we create is well-formed. We use the JIRA issue macro to create a link back to the issue. This will also create a remote link on the JIRA ticket:

image2014 10 5%2011%3A6%3A41
image2014 10 5%2011%3A7%3A53

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.