Confluence Groovy Runner

This simple plugin allows you to run Groovy scripts in the context of confluence. Groovy scripts have full access to the API.

This is in the same spirit as the Jira groovy runner, that is, it lets you quickly develop proofs of concepts and simple macros, without having to worry about all the boilerplate of a Confluence plugin, and the agonisingly slow edit-debug-deploy cycle (even with JavaRebel). Developing should be as simple as adding your macro, saving the page, make changes to your groovy script, then reload the page.

If you use IDEA (probably true of Eclipse too) you can attach the debugger, and break in to your groovy scripts.

Example page output from running the three supplied scripts:

conflu1.gif

Installation

  1. Download the jar (or source).
  2. Upload the plugin.
  3. Configure the plugin using the “Configure Plugin” link, then specify a directory on the confluence server under which your groovy scripts will live, eg /apps/confluence/scripts, or c:\apps\scripts.

Step 3 is necessary, if the macro user could specify anywhere on the confluence file system to run a script from, I imagine it would be possible for a user to upload a script as an attachment, work out what the path is on disk, then run the script to gain elevated permissions (or do anything else really).

So use a directory that only the confluence admins have write-access to.

Usage

Use the {groovy} macro. The body of the macro should be path the name of the file, beneath the trusted root, where your script lives. However, do not include the trusted directory itself. So, if your trusted dir is /apps/scripts and your script is in /apps/scripts/global/mymacro.groovy, the body of your macro should be just global/mymacro.groovy.

Note - the first groovy macro you run may take several seconds! After that it should be much quicker.

Example:

{groovy}ShowUserMacros.groovy{groovy}

There is one parameter you can pass, rendermode=NO_RENDER|ALL. If your script returns XHTML then set rendermode=NO_RENDER, if your script returns wiki markup then set the param to ALL or leave it out.

{groovy:rendermode=NO_RENDER}ShowPluginInfo.groovy{groovy}

Final example:

{groovy}ShowSpaceThemes.groovy{groovy}

The above scripts are included in the resource directory, and do what you would expect. To use them, extract them to a directory, ensure that directory is under your trusted root, then use the macro as above.

0 Responses to “Confluence Groovy Runner”


  1. No Comments

Leave a Reply

You must login to post a comment.






; Maximum allowed size for uploaded files. upload_max_filesize = 100M