Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Extend the Power Scripts add-on for Jira Server with your own functions

Hello!

The Power Scripts add-on lets you customize your Jira Server the way you need.

You can read more about the Power Scripts add-on and its features here.

In this article will will talk about the Server and Data Center versions of this plugin.

Power Scripts uses its own language called SIL. This language hides the complexity of Jira architecture and lets you customize Jira using SIL functions, which are very easy to learn and use.

But there is also a problem, if SIL does not have a function you need, then you can not use this function.

But it is not a reason to get disappointed, you can write this function yourself using Jira Java API.

Actually there are multiple cPrime plugins, which use SIL under the hood. For example, the Power Custom Field Premium PRO add-on or the Power Database Fields PRO add-on. 

You can add your own sil functions to all these plugins

In this article I will show you how to do it.

The source code for this plugin you can download here.

Create Jira Plugin

You need to install Atlassian SDK and after it you can execute the following command in the terminal:

atlas-create-jira-plugin

 This command will create a template for a Jira Server/Data Center plugin.

You will need to answer the questions in the terminal this way:

Define value for groupId: : ru.matveev.alexey.atlas.sil.extension
Define value for artifactId: : sil-extension
Define value for version:  1.0.0-SNAPSHOT: :
Define value for package:  ru.matveev.alexey.atlas.sil.extension: :
Y: : Y

Modify pom.xml file.

Your pom.xml file should look like this:

https://bitbucket.org/alex1mmm/sil-extension/src/master/pom.xml

Most important parts, which I added:

1. I added the path to cPrime repository to get the SIL library. We need this library to extend the sil language:

<repositories> 
  <repository>
    <id>cprime-internal</id>
<name>cprime maven repository</name>
    <url>http://maven.cprime.io/repository/maven-releases/</url>
</repository>
</repositories>

2. I added dependency for the SIL library:

<dependency> 
<groupId>com.keplerrominfo.jira.plugins</groupId>
<artifactId>katl-commons</artifactId>
<scope>provided</scope>
<version>${katlcommons.version}</version>
</dependency>

3. I made the SIL library be loaded during the start of our plugin:

<pluginArtifacts>
<pluginArtifact>
<groupId>com.keplerrominfo.jira.plugins</groupId>
<artifactId>katl-commons</artifactId>
<version>${katlcommons.version}</version>
</pluginArtifact>
</pluginArtifacts>
<pluginDependencies>
<!-- OBR dependencies -->
<pluginDependency>
<groupId>com.keplerrominfo.jira.plugins</groupId>
<artifactId>katl-commons</artifactId>
</pluginDependency>
</pluginDependencies>

Add files to add a new routine to the SIL language

 1. Add a java class for our new routine:

https://bitbucket.org/alex1mmm/sil-extension/src/master/src/main/java/ru/matveev/alexey/atlas/sil/extension/impl/ReverseStringRoutine.java

the executeRoutine function in this file is executed all the time our new routine called. You should put your logic there.

2. Add a java class with information of your plugin:

https://bitbucket.org/alex1mmm/sil-extension/src/master/src/main/java/ru/matveev/alexey/atlas/sil/extension/impl/ESPluginInfoService.java

In the getKey method you should return the key of your plugin plugin. If you return something else, then your routine will not be loaded.

3. Add a java class to load your routine to the SIL library:

https://bitbucket.org/alex1mmm/sil-extension/src/master/src/main/java/ru/matveev/alexey/atlas/sil/extension/impl/ESLauncher.java

Launch your plugin

Now you can start your plugin with the atlas-run command.

Atlas-run will start Jira and install your plugin in this Jira. 

After Jira started you can go to the SIL manager (http://locahost:2990/jira/plugins/servlet/silmanager) and write a script like this:

string str = myReverseString(summary);
logPrint("ERROR", "summary:" + summary);
logPrint("ERROR", "reversed summary:" + str);

Now if you execute this script, you will see the following lines in the atlassian-jira.log file:

2019-01-22 17:19:28,412 pool-32-thread-9 ERROR admin 1039x571x1 1ymwhmx 0:0:0:0:0:0:0:1 /rest/keplerrominfo/refapp/latest/async-script/runScriptFromEditor [c.k.s.lang.routines.LogPrintRoutine] summary:This is your first task
2019-01-22 17:19:28,415 pool-32-thread-9 ERROR admin 1039x571x1 1ymwhmx 0:0:0:0:0:0:0:1 /rest/keplerrominfo/refapp/latest/async-script/runScriptFromEditor [c.k.s.lang.routines.LogPrintRoutine] reversed summary:ksat tsrif ruoy si sihT

That is it. You can now write your own routines for SIL and extend cPrime plugins with new features. 

TAGS
AUG Leaders

Atlassian Community Events