Groovy scripts

On this page

Still need help?

The Atlassian Community is here for you.

Ask the community

You can run Groovy scripts in conditions and validators and post functions. They give you more power and flexibility, but are recommended for advanced users.

If you've enabled Groovy console or you're on Jira Service Management version lower than 5.16, refer to our previous documentation on configuring Groovy scripts.

Groovy scripts page in Assets configuration section

Before you start

Here’s some things to be know before you start using Groovy scripts:

  • You’ll need to be a Jira admin or Jira system administrator.
  • To start using Groovy scripts across Assets, add your scripts to the following directory in the shared home.
    <JIRA_SHARED_HOME>/plugins/assets/groovy_scripts
    You can also store the scripts within subdirectories of the above path and if you wish to store the files in a different location, create symbolic links
  • Make sure that the directory, the subdirectories where your Groovy scripts are located, and your Groovy script files are readable and executable by the user running Jira. We recommend that you limit the user accounts who can access the scripts directory.
  • Make sure to test your scripts in a non-production environment, before you run them in your production environment.

View and run a Groovy script

Once you’ve added a script to the script directory in the shared home, you can view the script contents and run the script.

You can also use any files added to the allowlist in the Groovy script configuration page before your upgrade to Jira Service Management 5.16.x. A read-only list of these scripts is available in the Groovy scripts page.

To view and run a script:

  1. Go to Administration  then Manage apps.
  2. Select Groovy scripts then View and run scripts.
  3. In the Script path field, enter the absolute file path. Paths can also be relative to the script directory.
    For allowlist scripts, enter the absolute file path.

  4. (optional) Add other details such as the Issue key and Object key.

  5. Select Run script.

You can also view and run scripts from other areas of Assets such as workflow transitions and object schema automations. Note that Assets Schema managers can also configure Groovy scripts within object schema automations.

Scripts paths with a prefix of {JWD} are files that you’ve stored relative to the Jira working directory before upgrading to Jira Service Management 5.16.


How to enable the Groovy script console

Starting from Jira Service Management 5.16x, the Groovy script console present in earlier versions is not available by default in Assets. Although you can use groovy console, to minimize potential security risks associated with arbitrary code execution, we advise against using it.

Here’s some things to know before you enable the console:

  • You can add or remove allowlist files in the Assets allowlist page.
  • You can continue to use files within the script directory across Assets even after you enable the console.
  • If you’re using scripts in post functions for Workflows, make sure to add them to the allowlist or the script directory.
  • Any script paths you’ve specified within Workflows (conditions, validators, post functions) will work but you can’t modify the script paths. 

To enable the groovy console feature flag, set the following system property. How to set system properties

assets.groovy.console.enabled = true

Variables

When adding a Groovy script, Assets workflow functions have the following variables pre-defined, so you can use them in your scripts.

VariableDescription
issueThe issue to be transitioned.
originalIssue

The original issue.

You can use the attributes of issues as conditions. For example, if you want something to happen if the assignee has changed, use the following code in your condition:

issue.assignee != originalIssue.assignee
currentUser

The current Jira user.

To check if the reporter is the current user, use the following code:

currentUser == issue.reporter
log

A log framework. You can log to atlassian-jira.log by:

log.warn("This is a warning!");


Examples

If you're looking for some inspiration and examples, see Groovy script examples 1.

Last modified on May 9, 2024

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.