Built-In Scripts
What are Built-in Scripts?
ScriptRunner built-in scripts to automate manual, complex, and time-consuming tasks. The flexibility of ScriptRunner for Jira lets you do almost anything with your data, meaning some routine tasks can become complicated and incredibly tedious. Aimed at users with limited Groovy knowledge, built-in scripts allow you to quickly achieve your goals without having to write Groovy code from scratch.
All built-in scripts are always visible and executable by users with Jira Administration and Jira System Administration permissions.
How to use Built-in Scripts
Built-in scripts have been created for some of the most commonly run tasks in ScriptRunner. For example we have scripts to:
- Modify the resolution field of multiple issues at once with the Bulk Fix Resolutions script.
- Copy the value of a field from one field to another in your instance with Copy Field Values.
- Switch User to complete tasks as a different user.
- Show all configured ScriptRunner scripts on your instance with the Script Registry.
Before you Start
See our Built-in Scripts Tutorial to learn about setting up and using built-in scripts.
Executing Built-In Scripts Remotely
It’s possible to automate use of built-in scripts, i.e. calling them programatically. All scripts take a JSON payload. Currently this is url-encoded… which is likely to change in the future.
The payload contains the names and values of the parameters, plus the name of the built-in script we want to execute. The easiest way to get these is to execute the Preview function, and copy the scriptParams parameter.
Curl example
As an example, let’s use the script which bulk imports custom field options. We need to post data similar to the following, which will add the three options AAA, BBB and CCC.
groovy{ "FIELD_FCS":"10208", "FIELD_IMPORT_VALUES":"AAA\nBBB\nCCC", "canned-script":"com.onresolve.scriptrunner.canned.jira.admin.BulkImportCustomFieldValues" }
Put the above in a file, in this example called add-opt.json. Now post this to the correct endpoint using curl:
groovy> curl -u admin:admin "http://<jira>/rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.jira.admin.BulkImportCustomFieldValues" -H "X-Atlassian-token: no-check" -H "Content-Type: application/json; charset=UTF-8" -H "Accept: application/json" --data "@add-opt.json" {"output":"Added 2 new option(s) to scheme: <b>Default Configuration Scheme for SelectListA</b> for custom field: <b>SelectListA</b>. 1 option(s) already existed"}
In all the examples, enter appropriate administrator credentials.
If there is an error running the script, you will get a 500 status code, and a message.
HttpBuilder example
You can call these from code, for example from Groovy. The following example executes the Test Runner script:
groovytestConfiguration = [ FIELD_SCAN_PACKAGES: "com.onresolve.jira,com.onresolve.base,com.acme.scriptrunner.test", FIELD_TEST : [ "com.onresolve.jira.AAASetupAllFixtures", ], ] restClient.request(POST, JSON) { uri.path = "/$product/rest/scriptrunner/latest/canned/com.onresolve.scriptrunner.canned.common.admin.RunUnitTests" send URLENC, [scriptParams: new JsonBuilder(testConfiguration)] }