The Adaptavist Group LogoDocumentation

Using Mosaic Templates with ScriptRunner for Jira Cloud

Create and populate your Mosaic Confluence templates by leveraging ScriptRunner for Jira.

This use case will show you how to:

  • Extract a Mosaic template's storage format
  • Encapsulate that format in reusable Groovy utility functions
  • Dynamically populate template content (for example, to-do lists derived from Jira issues)
  • Create Confluence pages via REST using the generated storage format

The end result is a reusable, scriptable mechanism for generating Mosaic-based pages without relying on manual template selection in the Confluence UI.

Prerequisites

Before proceeding, ensure you have:

  • Administrator access to the relevant Jira and Confluence instances.
  • ScriptRunner for Jira Cloud installed and configured.
  • Permission to create pages in the target Confluence space.
  • Familiarity with:
    • Groovy scripting
    • Jira JQL
    • Confluence REST APIs
    • Confluence storage format (XHTML)

High-Level Architecture

At a high level, the solution works as follows:

  1. A Mosaic template is created manually in Confluence.
  2. The template's storage format is retrieved and treated as the canonical structure.
  3. Groovy utility functions encapsulate that structure and expose parameters (for example, user name and to-do items).
  4. Jira issues are queried via JQL and transformed into domain objects (e.g. TodoItem).
  5. The populated storage format is sent to Confluence via REST to create a page.

Although the following example uses hard-coded template content, the same approach can be extended to dynamically retrieve template content via the Confluence REST API.

Step 1: Create and Inspect a Mosaic Template

  1. In Confluence, create a page using Mosaic and design the layout you want (for example, a table-based to-do list). Alternatively take a look at our pre-made templates.
  2. Save the page or template.
  3. Retrieve the storage format for that page by using the Confluence REST API ?expand=body.storage, or by inspecting it via ScriptRunner/REST tooling.

This storage format becomes the basis for your template logic.

In the example implementation, the storage format is hard-coded. For a production-ready solution, you should retrieve this dynamically so changes to the Mosaic template do not require code updates.

Step 2: Define Domain Objects

Create simple domain objects to represent the data you want to inject into the Mosaic template.

For example:

  • MosaicTodoItem
    • Priority
    • Task summary
    • Description
    • Additional metadata as required

These objects decouple Jira issue data from the Confluence storage format.

Step 3: Build a Template Utility Class

Create a Groovy utility class (for example, MosaicTemplates) that:

  • Accepts structured data (such as a list of TodoItem objects)
  • Injects that data into the Mosaic storage format
  • Returns a fully-formed Confluence storage document

Example Responsibility

todoList(userName, todoItems) -> String (storage format)
Internally, this function:
  • Iterates over the list of to-do items
  • Maps each item into the table rows defined by the Mosaic template
  • Preserves all required Mosaic markup and macros

This approach ensures the Mosaic layout remains intact while allowing dynamic content.

Step 4: Query Jira and Map Issues to Template Data

Using ScriptRunner for Jira:

  1. Execute a JQL query to retrieve relevant issues.
  2. For each issue:
    • Map priority → to-do priority
    • Map summary → task name
    • Map description → task description
  3. Convert the results into a list of MosaicTodoItem objects.
This keeps Jira-specific logic isolated from Confluence-specific rendering logic.

Step 5: Create the Confluence Page via REST

Once you have the populated storage format:

  1. Construct a REST request to the Confluence content endpoint.
  2. Provide:
    • Space key
    • Page title
    • Optional parent page ID
    • Body storage (generated by the template utility)
  3. Execute the request from ScriptRunner.
At this point, a new Confluence page is created using the Mosaic template structure, fully populated with data from Jira.

Step 6: Execute via the Script Console

During development and testing:

  1. Use the ScriptRunner Script Console in Jira
  2. Load and execute the page-creation script
  3. Validate:
    • Page creation success
    • Correct Mosaic layout rendering
    • Accurate data population
This feedback loop allows rapid iteration on both template structure and data mapping.

Optional Enhancements

This basic example can be enhanced in several ways, for example:

  • Dynamic template retrieval

    Fetch the Mosaic template storage format at runtime via REST.

  • Page metadata parameters

    Add parameters for:

    • Space key
    • Parent page
    • Labels
  • Higher-level abstractions

    Wrap page creation logic into a single function:

    createMosaicTodoPage(spaceKey, parentPageId, userName, jql)
  • Shared libraries

    Package utilities into a shared ScriptRunner library.

Result

When executed, the script:

  • Retrieves Jira issues
  • Converts them into structured to-do items
  • Generates Mosaic-compatible storage format
  • Creates a Confluence page that visually matches the original Mosaic template

This provides a repeatable, quick, automated mechanism for generating rich Confluence content directly from Jira data.

Summary

By combining ScriptRunner for Jira with Confluence's storage format, you can:

  • Treat Mosaic templates as code
  • Abstract layout concerns from business logic
  • Generate consistent, high-quality pages programmatically

This approach scales well for teams that rely heavily on Jira-driven reporting and structured Confluence documentation.

Search documentation

Start typing to search the docs.