Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Part 2 How to deploy Adaptivist ScriptRunner scripts and objects

In the first part of this article we created several scripts, packaged them into a plugin, installed the plugin and called one of the scripts from the Script Console.

In this part of the article we will try to deploy ScriptRunner objects such as a Listener, a REST endpoint, a Script fragment and a Scripted field.

You can take the source code of the plugin here.

Create a Listener, a REST endpoint and a Script fragment

Let's first create a listener, a REST endpoint and a script fragment in our dev environment. 

The first listener is a custom listener:

custom listenwe.pngThe second listener is the Adds the current user as a watcher listener:

list.pngThe REST endpoint looks like this:

rest.pngThe Script fragment looks like this:

webitem.pngAfter we created all the items we need to add them to our plugin so that the items would be installed after our plugin installation.

Go to Add-ons->Built-In Scripts->Configuration Exporter and choose all our created objects.

push.pngPush the Run button and you will see something like this:


Copy all the text in the selected red rectangle and add it to the src/main/resources/scriptrunner.yaml file. The file will look like this:

FIELD_KEY: ru-matveev-alexey-web-item
- ''
- ''
FIELD_SECTION: add-attachments-link
canned-script: com.onresolve.scriptrunner.canned.jira.fragments.CustomWebItem
id: '520053084'
FIELD_SCRIPT_FILE: ru/matveev/alexey/main/rest/rest.groovy
id: '-168713291'
- FIELD_FUNCTION_ID: cf09831f83bc75ec27076557034b952dfc727040
canned-script: com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener
clazz: ru/matveev/alexey/main/listeners/listener.groovy
- 1
id: '-586588827'
params: '{"FIELD_LISTENER_NOTES":"Custom Listener","projects":"","events":"1","FIELD_INLINE_SCRIPT":"","clazz":"ru/matveev/alexey/main/listeners/listener.groovy","FIELD_FUNCTION_ID":"cf09831f83bc75ec27076557034b952dfc727040","canned-script":"com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener","id":"-268926325"}'
- ''
FIELD_LISTENER_NOTES: Add the current user as a watcher
canned-script: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.AddWatcher
- 1
params: '{"FIELD_LISTENER_NOTES":"Add the current user as a watcher","projects":"","events":"1","FIELD_CONDITION":["",""],"FIELD_FUNCTION_ID":"","canned-script":"com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.AddWatcher"}'
- ''

Add the scripted field 

Unfortunately, the Export Configuration option can not export scripted fields. That is why we need to create scripted fields in our code. We will use the Upgrade Task feature of Jira. The Upgrade Task lets you launch a piece of code on plugin startup. An upgrade task will be executed only if it has never been executed yet. You need to make a class, which will implement the PluginUpgradeTask interface. Also this class must be exported as a public service.

First we create the src/main/groovy/ru/matveev/alexey/scriptedfields/AbstractUpgradeTask.groovy file (this file is taken for the sample ScriptRunner plugin):

package ru.matveev.alexey.scriptedfields

import com.atlassian.plugin.osgi.util.OsgiHeaderUtil
import groovy.util.logging.Log4j;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

abstract class AbstractUpgradeTask {
public String getPluginKey() {
Bundle bundle = FrameworkUtil.getBundle(AbstractUpgradeTask.class);
return OsgiHeaderUtil.getPluginKey(bundle);

This class implements the getPluginKey method, which is one of the methods of the PluginUpgradeTask interface. This method returns the plugin key.

Then we create src/main/groovy/ru/matveev/alexey/scriptedfields/CreateScriptFieldUpgradeTask.groovy(this script was taken from the sample ScriptRunner plugin):

package ru.matveev.alexey.scriptedfields

import com.atlassian.jira.issue.context.GlobalIssueContext
import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService
import com.atlassian.sal.api.message.Message
import com.atlassian.sal.api.upgrade.PluginUpgradeTask
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.test.ScriptFieldCreationInfo
import groovy.util.logging.Log4j

import javax.inject.Named

class CreateScriptFieldUpgradeTask extends AbstractUpgradeTask implements PluginUpgradeTask {

int getBuildNumber() {
return 1

String getShortDescription() {
return "This upgrade task creates a scripted field"

Collection<Message> doUpgrade() throws Exception {
def scriptFieldCreation = ScriptFieldCreationInfo.Builder.newBuilder()
.setSearcherKey(ScriptRunnerImpl.PLUGIN_KEY + ":exactnumber")
return null


This class is created as a public service, it extends the AbstractUpgradeTask and implements the PluginUpgradeTask. The doUpgrade method creates our custom field.

Test the plugin

You can open Terminal and execute atlas-run or you can install a Jira instance and add the plugin. As a result you will see the that all our object were created.

Our scripted field:

scriptedfield.jpgOur listeners:

listeners.jpgOur REST endpoint:

 rest.jpgOur Web fragment:

scriptfra.jpgWe can see all our object, which means that we successfully created all the ScriptRunner objects.

Now you can deploy our scripts and objects to any Jira environment by installing the developed in this article plugin.



Thanks for share your knowledge! 



Gonchik Tsymzhitov

This is very useful for Jira admins of Jira instances with a lot of ScriptRunner configuration. I'm glad to see the links to the Adaptavist doc and source pages

I love the power that ScriptRunner adds to Jira. Thanks for the article.

Ollie Guan Community Leader May 20, 2018

Thanks for share your knowledge! 

Hello, I don't really understand how can I deploy my scriptedfields.

I need to edit the file CreateScriptFieldUpgradeTask.groovy and put in the doUpgrade method all of my scripted fields (more than 20...) ?

Deleted user Nov 21, 2018

Thanks for sharing! But I have some follow up questions in this post. Can you maybe provide some help?

Great article! Here I found the example of a scripted field creation but could someone provide an example of how to create behaviours via code?

As I understand it's similar to the code for scripted fields but I couldn't find any example.

According to the documentation and Adaptavist support it is currently not possible to create behaviours via code, but they can be created and mapped via the REST API described here 

@Alexey Matveev _Appfire_ :  Thanks for sharing this information. Is it similar for Confluence Scriptrunner? 


Log in or Sign up to comment

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you