Store all Environment Specific Variables
Learn to write and test your ScriptRunner scripts on a test/development instance before migrating over to your production instance.
Manually editing environment-specific variables in each custom script is time-consuming and prone to errors. We suggest you use names rather than IDs in scripts as the name of custom components do not typically change when migrating to a production instance.
Sometimes, there can be multiple components (such as custom fields) with the same name. When this is the case, we suggest searching for the field name in the context of the issue you have.
For example, in Jira, you could run the following:
import static com.atlassian.jira.component.ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).findByName('Approvals')Storing Variables
If you can't use names as suggested above, then you need to abstract the IDs to a centralised place to avoid hard-coding them in multiple scripts.
Here we describe two ways of doing that - one using a simple java class that varies between environments, and the second one which reads configuration from a YAML file. Storing variables in the application home directory, or an environment-specific class, removes the need to edit custom scripts manually.
Java Class
YAML File
One way of storing environment-specific variables is to create a class which will read a YAML file. Below is an example YAML file but this method works with any valid YAML file:
Approvals: customfield_12345
Long Custom Field Name: customfield_56789