Set Up a Dev Environment
A guide for users who would like to set up a development environment to meet their needs in ScriptRunner for Confluence Data Center.
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 three 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)
- Continuous integration
- 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.
Requirements
The software and hardware requirements for this guide follow:
Software
- Java SE Development Kit 8 (JDK 8)
- Git
- IntelliJ IDEA
- Atlassian-SDK
- Atlassian Maven (installed with the Atlassian SDK)
Which Maven
We recommend using the Maven binary shipped with the atlassian SDK as this is Atlassian's own implementation of Maven specifically designed for use with developing atlassian plugins. Standard Maven installations might not be able to resolve all the required dependencies without additional configurations.
You can find how to install the atlassian SDK here:
Once installed you will need to know where the Maven binaries are located (e.g: atlas-mvn). You can find this by running:
atlas-version (Look for the ATLAS Maven Home value)
Inside IntelliJ, you can then configure your Maven configuration to point to the atlassian Maven binaries using the ATLAS Maven Home directory as the Maven home path.
Hardware
Your memory needs vary based on the Atlassian host application that you're working with. Here are Atlassian's recommendations:
- Jira - 2GB of RAM
- Confluence - 6GB of RAM
- Bitbucket - 3GB of RAM
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
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.
- Configure a Global SDK .
- Configure your Project SDK .
- Configure your Module SDK .
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.
Script Roots Information
The base pom adds the following script roots to the development environment only:
<module>/src/main/resources<module>/src/test/resources<module>/src/test/groovy
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).
atlas-mvn:<product>:debug you have to access the scripts stored inside your custom plugin using the package names defined insiFor example, a script that is created inside the development environment with this structure:
de your scripts./scriptrunner-samples/jira/src/main/resources/com/myscripts/someScript.groovy
and this package declaration is at the top of the someScript.groovy file:
package com.myscripts
will need to be accessed like this from any ScriptRunner script file reference:
/com/myscripts/HelperMethods.groovy
Note: auto-completion for scripts inside the custom script plugin jar is currently broken, so you will need to manually type the path to the file using the above logic.
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:
Debug a Groovy Script
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:
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).Customize the Scriptrunner version
If you want the development environment to start with a specific ScriptRunner version you can override the default by adding a property to your application-specific local pom file.
For example:
atlas-mvn jira:debug you can edit the /scriptrunner-samples/jira/pom.xml file and inside the properties XML tag add:
<scriptrunner.version>6.40.0</scriptrunner.version>Adding Additional Applications
Adding additional applications is done inside the <applications> block.
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:
<applications>
<!-- Include Jira Software features -->
<!--
<application>
<applicationKey>jira-software</applicationKey>
<version>${jira.software.version}</version>
</application>
-->
<!-- Include Jira Service Desk features -->
<!--
<application>
<applicationKey>jira-servicedesk</applicationKey>
<version>${jira.servicedesk.version}</version>
</application>
-->
</applications>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:
<httpPort> entry to the configuration block of your AMPS plugin (jira-maven-plugin, confluence-maven-plugin, bitbucket-maven-plugin).<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>jira-maven-plugin</artifactId>
<configuration>
<!-- Other code here... -->
<httpPort>2990</httpPort>
<!-- Other code here... -->
</configuration>
</plugin>Go Further
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 :debug Maven goal to test it. As your script library grows, you may find you need even more out of your local development environment.
Development Lifecycle
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 Creating 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.
Execute Tests
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 . 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.
Useful links
See the following links for more information:
- Apache Groovy documentation
- See the Bitbucket API Reference
- See the Atlassian Answers questions tagged as ScriptRunner-related