Script Manager
Learn how to use the Script Manager to create, manage, and run scripts in your Jira instance.
Migrating from ScriptRunner for Jira Server/DC to Cloud? Check out our ScriptRunner Migration to Cloud section. |
Before you start
Check out our demo videos to learn about reusing and organising code with Script Manager. |
What is the Script Manager?
The Script Manager feature in ScriptRunner for Jira Cloud allows you to manage saved .groovy and .jel scripts and folders directly from the ScriptRunner front-end. It enables you to create and manage scripts and folders within your instance without relying on FTP services or server administrators.
With Script Manager, you can easily reuse and organize scripts in any of the Groovy and Jira Expression Language code editors across your instance, making script management more efficient and accessible.
For example, if you had the same logic across multiple scripts and needed to update such scripts, you previously had to make the change in several places. With Script Manager, you can write the code once and reuse it wherever needed. When it's time to update it, you modify it in one place, and the change is automatically reflected across all occurrences.
Create folders
To add a new folder, follow these steps:
Create scripts
To add a new script, follow these steps:
Edit existing scripts
To edit saved .groovy or .jel scripts, follow these steps:
Rename existing scripts and folders
To rename an existing script or folder, follow these steps:
Move existing scripts and folders
To move an existing script or folder, follow these steps:
Duplicate existing scripts
To duplicate an existing script, follow these steps:
Delete scripts and folders
To delete .groovy or .jel script files and folders, follow these steps:
How to reuse scripts
Reuse scripts in the UI
As an example, let's choose to create a new Scheduled Job.
Reuse scripts by importing reusable Groovy code
You can import reusable .groovy code into existing or new scripts, and you can create .groovy classes or scripts to organise shared logic. This allows you to structure your code into classes and packages, and to import scripts directly where needed.
ScriptRunner leverages Groovy's program structure, which allows for importing and reusing code from classes and scripts. ScriptRunner treats the code stored in Script Manager as a .groovy codebase, and all Groovy scripts in ScriptRunner have contextual awareness of the code in Script Manager. This means that if you are writing the same function for two Script Listeners and duplicating the code in both places, you can instead place that logic in a utility script or class in Script Manager, then import and reuse it wherever you need it.
Example of code reuse using classes
LinkUtils.groovy
This class contains a utility method that will search all work items in a given space and summarize the key and number of blockers against each work item that is blocked.
package utils
class LinksUtils {
static Map<String, Integer> getBlockedItemsByProject(String project) {
Issues.search("project = ${project}").collectEntries {
def blockers = it.getLinks().findAll { it.type.inward == 'is blocked by'}.collect()
return [(it.key) : blockers.size()]
}.findAll {
key, value -> value as int > 0
}
}
}We can use the above code in a script as follows:
import utils.LinksUtils
LinksUtils.getBlockedItemsByProject('DEMO')package utils - In Groovy, a package reflects the parent folder structure of the code's location. The package helps Groovy identify a class, and you need to reference it when importing code into your scripts. For example, you can see how we imported the code for reuse using the following statement: import utils.LinksUtils
PrintFormatter.groovyin the Script Manager codebase screenshot above, you cannot import and reuse that code in other scripts or classes that belong to named packages.Example of code reuse using scripts
Groovy also allows us to import and reuse scripts without the need to declare classes. There are multiple options for doing this.
reusablescript.groovy
A simple Groovy script that defines a method that takes an argument called name and returns a greeting.
package com.myapp.simplescripts
println "Script loaded!"
def greet(name) { "Hello, $name!" }Importing and reusing a part of the script:
import com.myapp.simplescripts.reusablescript
def script = new reusablescript()
script.greet('Admin')The package path must match your directory structure: com/myapp/simplescripts/reusablescript.groovy. You will need to provide the package structure when organizing scripts for reuse via imports.
You can call specific methods declared in the script, or you can use .run() to run the entire script. Using a script works similarly to using a class because, in the background, each .groovy file automatically becomes a class you can instantiate.