Scripting
You can access features of Configuration Management Toolkit from Groovy Scripts without need of any 3rd party application like ScriptRunner. Of course you can continue to access the add-on’s services from ScriptRunner if you want but starting with our 1.16.0 version you don’t need any 3rd party add-on.
You can access the app’s API here. Note that this API is for latest version of the app, please contact us if you need previous version of the API.
Configuring scripts requires Jira Administrator or Jira System Administrator permission because a script may execute any code on your system and potentially do anything including deleting your data.
Scripts is located under “Configuration Management Toolkit” section of “Manage apps” section.
Adding a New Script
Click on “Add Script” button. This will open “Add Script” dialog. Scripts are run as a response to events so you should select at least one event. You can also restrict a script to selected projects if you want. This is recommended so that script will not be executed unnecessarily.
As you know, Groovy Scripts are dynamically typed, that is you don’t need to specify type of parameters when writing code. This will make scripts more readable and easier to write but you may make more error. To reduce the number of errors you can opt-in for “Static Type Check” by checking “Static Type Check” toggle at the bottom of “Script Dialog”. In “Static Type Checking” mode, editor may show some errors but this may be due to you are not specifying correct type information while writing code. If you are sure your code is correct, you can continue and save the script it will most probably run without any issues. Remember that, Groovy Scripts are dynamically typed, you don’t need to specify type information.
Debugging Your Scripts
You can use println statements to log values to Jira process's standard output for debugging purposes, not atlassian-jira.log file. You can use SLF4J logging to log to atlassian-jira.log file if you want. If you want to use logging please set debug level for the package "com.deniz.jira.versioning.scripting" and use following code to add debug messages to your script.
import org.slf4j.*;
//please enable logging for package "com.deniz.jira.versioning.scripting" from Administration/System/Logging and Profiling
Logger log = LoggerFactory.getLogger(com.deniz.jira.versioning.scripting.ScriptingService.class);
log.debug("This is debug message"); |
Sample Scripts
You can use following scripts for starting point for your own scripts. Please let us know if you need help while writing scripts, we can help you to write it a lot easier.