Who This Guide Is For
We recommend this guide for users who:
Write or maintain a large number (10+) of custom scripts regularly
Collaborate on a team of 3 developers or more
Want to implement standard software development practices (and tools) alongside their scripts, for example:
Version control (Git)
Configuration as code (YAML)
Automated testing (Spock)
Want to keep their scripts in a centralized place that isn’t simply a script root directory on their server
Want all the benefits of working with IntelliJ IDEA, for example:
Efficient script-writing and less log hunting
Quick access to the Atlassian APIs
Code auto-completion, syntax checks, and other IDE features
This is a quick-start guide for users who could benefit from connecting ScriptRunner to tools such as Git, IntelliJ, and Maven, without mastering them. The goal is to give useful tools to the average scripter without holding back more experienced developers.
This guide is NOT a detailed guide on how to use tools like Git, IntelliJ, and Maven. If you are looking for those detailed instructions, you will have to consult each product’s own documentation.
The software and hardware requirements for this guide follow:
Your memory needs vary based on the Atlassian host application that you’re working with. Here are Atlassian’s recommendations:
Experienced Atlassian plugin developers recommend 16GB of RAM on your development computer if possible, particularly as you run more and more things to test and debug your application (IntelliJ, the Atlassian application, multiple web browsers, etc.).
The ScriptRunner Samples Project
This project contains script plugins for the ScriptRunner Suite (Jira, Confluence, and Bitbucket Server). The following tasks lead you through working with the Scriptrunner Samples project to connect the tools.
Import the Project into IntelliJ
Once the project has been imported, IntelliJ downloads dependencies.
This takes a while, but let it finish before moving on to the next task.
Set a JDK for the Project
Java Development Kit 8 should be configured as the SDK for the project. There’s a chance the SDK may already be configured, but if not, you can find instructions by clicking the links below.
Each screenshot represents approximately how your configuration should look.
Build and Run Jira/Confluence/Bitbucket with the Sample Plugin
If you have fulfilled the above requirements and tasks, you should now be able to build the sample plugins.
Inside a terminal, you can start each application with its respective command:
Those commands should start a locally running instance of the application at:
http://localhost:8080/<application>and you should see something like this in your terminal:
Login using the following credentials:
Complete the application’s setup screens, if prompted.
Test to make sure everything has started properly by following these steps:
Navigate to the Script Console, and then switch to the File tab.
Start typing the name of the sample script that’s installed in each plugin (
ScratchScript.groovy), and then click the suggestion.
You should see the string returned by that script in the Results tab.
Script Roots Information
The base pom adds the following script roots:
Any scripts inside these directories can be run from the Script Console (or any other ScriptRunner extension point such as event listeners) without specifying a full path (like you did with the
ScratchScript.groovy file above).
Advanced IntelliJ IDEA Configurations
Read on for some advanced configuration options that will make your scripting experience even better.
Create Debug Configuration in IDEA
A debugger can be helpful for complex scripts. Follow these steps to create a run configuration for starting a debugger:
Select Run > Edit Configurations in the top menu bar.
Press the + button, and then select Remote.
Set a name for your debug configuration (e.g. "Jira").
Set the debug port to 5005.
Click on the Logs tab, and then press the + button.
Enter an Alias (e.g. Jira logs).
Navigate to the location of your logs by using the Browse button.
The log files should be at the following locations:
Jira - scriptrunner-samples/jira/target/jira/home/log/atlassian-jira.log
Bitbucket - scriptrunner-samples/bitbucket/target/bitbucket/home/log/atlassian-bitbucket.log
Confluence - The log file is not be present in the target directory, but it is written to the Console tab in IntelliJ when you run
targetdirectory is only present if the application has been previously built. If you’ve followed all of the tasks in this guide, you completed this in the Build and Run Jira/Confluence/Bitbucket with the Sample Plugin section.
The debug configuration should look approximately like this:
- Click Apply, and then click OK.
Since you already started the application in the previous steps, click Run > Debug Jira (or whichever debugger you created) to start debugging your application.
That action starts the debugger, and a window like this one should show up in a lower area of IDEA:
Debug a Groovy Script
You can use the debugger you just created with a Groovy script.
In IDEA, open ScratchScript.groovy.
Each application has its own so make sure you open the correct one.
Set a Breakpoint on the line the string begins on.
Execute your script via the Script Console.
The debugger should stop the execution of the script at the location of your breakpoint.
Use the inspector to:
Step through the code
Mid-execution, look at the values of variables in your script
Mid-execution, evaluate a Groovy code fragment
Click the green run button to resume the execution.
Connecting IntelliJ IDEA with the Atlassian Source Code
One of the biggest benefits of writing your code in IDEA is that you can access the JavaDoc directly in the IDE instead of needing to go to the API’s documentation website.
If you have purchased a license from an Atlassian product, you will have access to the Source Download page.
Using Jira as an example, follow these steps to create a new Groovy script to see the connection working:
Create a new file called UsersCount.groovy inside the
Use the following code in the file:
Run UsersCount.groov using the Script Console.
In the Logs tab, you can see a message stating "My instance contains X users."
You should see the same message in the Jira Logs tab of your IntelliJ debugger.
Browse the Java API
UserManager class can do many different things. Follow one of these steps to explore its capabilities.
In IntelliJ, type
userManager., and you will see the properties and methods available to be used.
In, IntelliJ, navigate to the class file itself by holding down CTRL (or CMD in OSX) and clicking on the class name. Try this for the
UserManagerclass located at the end of line 4. You will see something like this:
The decompiler already gives you a lot of information about the class, but you can go even further and see the entire implementation of it.
If you click the Choose Sources… link, and then select the folder that contains the application’s source (which you downloaded earlier), the source for the class is shown. Then, the IDE will provide better parameter names and inline JavaDoc.
You may have to do this multiple times, once for each dependency (
jira-servicedesketc). In each case, just point to the root of the downloaded sources, select everything, and let IDEA configure it.
Advanced Plugin Configuration
There are a number of settings in the plugin’s
pom.xml file that you may want to change to suit your needs while writing your scripts.
Customize Product Versions
The project’s parent pom sets a lot of default values for the versions of the libraries to be used when writing your scripts. Those default values can be changed if you are going to write scripts for a different version of the Atlassian applications. You can change them by editing the
<properties> section of your pom.xml.
For example, to set the Jira version to 7.13.11, your properties block might look like:
<properties> <jira.version>7.13.11</jira.version> </properties>
<confluence.version> for Confluence,
<bitbucket.version> for Bitbucket (in their respective pom.xml).
Adding Additional Applications
Adding additional applications is done inside the
For example, if you are writing a plugin for Jira, you may require Jira Software, or Jira Service Management. Those two have been added to
jira/pom.xml for you, but for others you will need to add them. To make sure they get installed, uncomment out the application(s) you would like. An example of this code is shown below:
If you are going to install Jira Service Management, make sure its version is compatible with your Jira version.
Changing the Default HTTP Port
The base pom sets all applications to run on port 8080 for consistency, rather than their defaults. That can be changed by adding a
<httpPort> entry to the configuration block of your AMPS plugin (jira-maven-plugin, confluence-maven-plugin, bitbucket-maven-plugin). An example of this code is shown below:
<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>jira-maven-plugin</artifactId> <configuration> <!-- Other code here... --> <httpPort>2990</httpPort> <!-- Other code here... --> </configuration> </plugin>
The next time you want to create and debug a new script, you will just need to add a new Groovy script to your IDEA project and run the <application>:debug Maven goal to test it. As your script library grows, you may find you need even more out of your local development environment.
Do you find copying and pasting scripts between IntelliJ and the ScriptRunner web interface tedious? There are two better ways: the Script Editor and a script plugin.
Using the Script Editor, you can edit and create files directly from ScriptRunner’s UI. Check out the ScriptRunner Script Editor documentation for more information.
The whole environment you just set up is actually a full blown Atlassin plugin development. Take a look at the documentation on Create a Script Plugin for more information on how to use that environment to develop and package your scripts for deployment in test and production instances.
For automated testing in ScriptRunner in the project that you just set up, you can add tests under
<module>/src/test/resources. You can then run them with our built-in script located under Administration > Built-In Scripts > Test Runner. See Test Your Code documentation for more information.
Use an External Tool for Running Scripts Against Jira/Confluence/Bitbucket
One handy tool for debugging is adding an external tool in IntelliJ to run an arbitrary Groovy script against ScriptRunner.
We will use Jira as an example, but the same can be done for Confluence and Bitbucket.
Navigate to IntelliJ Preferences > Tools > External Tools.
+and fill in the following fields:
Run in Jira
-u admin:admin --header "X-Atlassian-token: no-check" -X POST --data "scriptFile=$FilePathRelativeToSourcepath$" http://localhost:8080/jira/rest/scriptrunner/latest/user/exec/
Make sure your application’s base URL and port are correct.
The fields should look like this:
Invoke the test by running Tools > External Tools > Run in Jira in the top menu bar of IntelliJ.
POSTthe body of the script file you’re working with to your locally running Jira server and execute it, just as if you’d copy-and-pasted the code into the Script Console and clicked Run.
See the following links for more information: