Scripting in ScriptRunner for Jira Cloud

Overview

ScriptRunner for Jira Cloud domain allowlist

We advise all customers with a Cloud firewall to ensure that access to the *.connect.product.adaptavist.com wildcard URL is permitted. You can refer to Use IP Addresses for more details.

ScriptRunner for Jira Cloud allows you to extend the functionality of Jira Cloud, executing scripts to interact with Jira as Workflow Extensions or Script Listeners. Scripts can be useful for automating regular actions, such as updating an issue during a transition or performing a calculation and storing the result in a custom field on the issue.

Outlined below are the various programming languages used for scripting and their associated features within ScriptRunner for Jira Cloud:

Script Variables

Scripting is not used for this feature, it utilises two fields to add a variable which you can call out in other scripts, such as password.

Groovy

Utilising the Groovy programming language you can respond to events and transitions and manipulate Jira using the REST API. Additionally, you can use the Enhanced Search feature to run ScriptRunner Enhanced Search JQL Functions in Jira Cloud and create filters for dashboards and scrum boards that use those functions.

Scripts using the Groovy language include Post Functions, Scripted Fields, Script Listeners, and Scheduled Jobs. Check out our HAPI section on updating your scripts to make them more manageable.

Typescript/Javascript

ScriptRunner for Jira Cloud uses Typescript/Javascript for the Behaviours feature, and the Script Fragments feature uses Javascript.

Jira expressions

Jira expressions are used for conditions and validators along with some script execution conditions. Check out our Example Conditions and Validators.

JQL

A JQL query is required for the bulk clone issues built-in script, and a filter (created from JQL) for the bulk fix resolution built-in script.

Example scripts

Check out our extensive list of ScriptRunner for Jira Cloud examples scripts on the ScriptRunner HQ website.

HAPI

HAPI is an API used for carrying out common tasks in Jira. These can include managing or searching for issues, updating fields and more. HAPI s essentially plain Groovy, but it gives you a simpler alternative to Jira's regular API and you can mix and match HAPI calls with Jira API. 

HAPI does not require you to rewrite existing scripts. However, should you wish to make your current scripts more manageable then you might want to update them to use HAPI. Read all about it in our HAPI section.

Code editor

Use the code editor to write scripts in ScriptRunner. The code editors use an intelligent code editor. The browser-based code editor provides code completions, inline Javadoc lookups, inline find and replace, and error line indication. This editor has autocomplete for the following code: 

  • Groovy
  • Atlassian REST API
  • Automatically available variables

Keyboard shortcuts warning

Keyboard shortcuts may not work depending on other system-defined shortcuts.

Completions

The code editor automatically displays suggestions as you type. Suggestions are filtered as you type, so only relevant options are displayed. Use the arrow keys and Enter or Tab to select a suggestion. You can manually trigger completions with Control+Space.

When referring to a class, the code editor automatically adds the required import.

To save typing, use camel case abbreviations.

Smart completions 

Press Ctrl+Alt+Space to show a list of completions that match the expected type of assignment or parameter type.

Parameters 

When typing method parameters, it is easy to forget the expected types. Parameter types and, where possible, names are shown for the given method. Use the up/down cursor keys to scroll through any available overloads.

Press Control+Shift+Space to view parameters when inside a method.

Javadoc

The code editor can help you understand the purpose of classes, methods, and properties by loading the associated Javadoc. The Javadoc is shown in the editor as a pop-up. To view the Javadoc, press Control+Space with completions open. It will be displayed automatically from then on. To close it, press Control+Space again. 

Find and replace

You can use the code editor to find and replace in the code editor. To access find and replace, press ⌘+F (Mac) or Ctrl+F (Windows).
To search for text, enter it in the Find field. To access find and replace, press Option+⌘+F (Mac) or either Ctrl+H or Alt+Ctrl+F (Windows). 

Error line indicator

Errors in your script are highlighted in the right-hand panel of the script editor. Errors are highlighted inline, on the scroll bar, and in the right-hand overview ruler. When you have located an error, hover over the error with the cursor to see a summary.

Full-screen editing

To open the script editor in full screen, click the icon  or press F11 when the cursor is in the editor. To exit the full screen, press F11 or Esc twice when the cursor is in the editor. 

Restrictions

The code editor has some limitations; work is ongoing to reduce these limitations. As mentioned, Javadoc for Bamboo APIs and ScriptRunner’s API (e.g. Behaviours) are unavailable. However, completions and parameter hints are available for all.


On this page