Script Console

What is the Script Console?

The Script Console is the place for running one-off ad hoc scripts, and for learning and experimenting with the Jira REST API and HAPI.

You can either enter your script directly in the Script field, or click the File tab, and type the path to a file. The file can be a fully-qualified path name to a .groovy file accessible to the server. If you provide a relative path name the file is resolved relative to your script roots.

How to use the Script Console

You can use the Script Console to:

  • Run a script to display information.
  • Run a one-off clean up task.
  • Bulk update issues, projects, users, versions etc

For example, as an admin you have been given a list of users who have left the company. For security reasons, you need to remove these users as soon as possible. Usually, you would need to search for each name individually and manually delete each user. However, I can enter the list of user names and bulk delete all of them in one action using a script in the Script Console.

Using the Script Console is an easy way to make bulk changes to issues returned by a JQL query. For example, I can look for issues with linked support cases and no watchers so I can then automatically add the linked support cases reporter to the related bug as a watcher.

Before you start

See our Introduction to Scripting in ScriptRunner course to learn about using Groovy to write new scripts, and modify existing scripts in ScriptRunner.


Broaden your horizons by exploring the Adaptavist Library for Script Console script examples.

Executing Script Console scripts remotely

You can also execute arbitrary code in the Script Console remotely. Due to the url encoding this is a bit finicky. Assuming we have the following code in a file called script.groovy

groovy
script.groovy log.debug ("hello") log.debug ("sailor")

We can execute it using the following curl command:

bash
curl -u admin:admin -X POST "http://<jira>/jira/rest/scriptrunner/latest/user/exec/" -H "X-Atlassian-token: no-check" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" --data-urlencode "scriptText@script.groovy"

To execute a file that already exists under a script root:

bash
curl -u admin:admin -X POST "http://<jira>/jira/rest/scriptrunner/latest/user/exec/" -H "X-Atlassian-token: no-check" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" --data-urlencode "scriptFile=foo/bar.groovy"

Related content

On this page