Home Blog ScriptRunner – Write Hello World Program in Jira | Groovy

ScriptRunner – Write Hello World Program in Jira | Groovy


Welcome to a complete tutorial on how to write a Hello World program in Jira using ScriptRunner and Groovy! Whether you are a Jira beginner or an experienced user, this article will provide you with step-by-step instructions, examples, and answers to commonly asked questions.

ScriptRunner is a powerful add-on for Jira that allows you to extend its functionalities using Groovy scripts. Groovy is a dynamic scripting language for the Java platform, making it a perfect choice for developing scripts within Jira.

To get started, follow these simple steps:

Step 1: Install ScriptRunner
– Open Jira and navigate to the “Administration” section.
– Click on “Manage apps” and search for ScriptRunner.
– Install ScriptRunner and follow the instructions to set it up.

Step 2: Create a new script file
– In ScriptRunner, go to “Script Console” under the “ScriptRunner” menu.
– Click on “Create” to create a new script file.

Step 3: Write the Hello World program
– Give a name to your script (e.g., HelloWorld.groovy).
– In the script editor, write the following code:

def message = “Hello, World!”
return message

Step 4: Run the script
– Click on the “Run” button to execute the script.

Congratulations! You have successfully written and executed your first Hello World program in Jira using ScriptRunner and Groovy. The script will output “Hello, World!” in the console.

Now that you have the basics, let’s explore some examples to understand more about ScriptRunner and Groovy scripting in Jira.

Example 1: Create a Comment on an Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey(“KEY-123”)
def commentManager = ComponentAccessor.commentManager
def comment = commentManager.create(issue, ComponentAccessor.jiraAuthenticationContext.loggedInUser, “This is a comment.”)
commentManager.update(issue, comment)

Example 2: Add a Label to an Issue
import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey(“KEY-456”)
issue.labels = [“label1”, “label2”]

These examples demonstrate some of the capabilities of ScriptRunner and how you can automate tasks in Jira using Groovy scripts.


Q: Can I schedule scripts to run at specific times?
A: Yes, ScriptRunner provides options to schedule scripts using cron expressions.

Q: Can I access Jira APIs in my scripts?
A: Absolutely! You can import and use Jira APIs to interact with Jira objects and perform various operations.

Q: Are there any restrictions on what I can do with ScriptRunner?
A: ScriptRunner provides extensive capabilities, but it is important to adhere to Jira’s security policies and best practices.

In conclusion, ScriptRunner and Groovy scripting offer powerful features to extend Jira’s functionalities and automate tasks. With this complete tutorial, examples, and Q&A, you are now equipped to start writing your own scripts in Jira. So go ahead, experiment, and enhance your Jira experience with ScriptRunner!

ScriptRunner for Jira is a powerful plugin that allows users to write custom scripts and automation rules in Groovy to enhance their Jira workflows. Whether you’re a beginner or an expert in scripting, ScriptRunner provides a user-friendly interface that allows you to automate various tasks and customize Jira according to your needs.

One of the simplest ways to get started with ScriptRunner is by writing a “Hello World” program. This program typically serves as a starting point for beginners to understand the fundamentals of scripting in Jira.

To begin, make sure you have ScriptRunner installed in your Jira instance. Once installed, navigate to the “Script Console” in Jira administration. Here, you can start writing your first program.

In Groovy, the scripting language used by ScriptRunner, a “Hello World” program is as simple as writing a few lines of code. Let’s write one together:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (currentUser) {
} else {
“Hello World”

This code snippet checks if a user is currently logged in to Jira. If a user is logged in, it retrieves the display name of the user, otherwise it simply returns “Hello World”.

Now, when you run this script in the Script Console, it will display the logged-in user’s name or “Hello World” if no user is logged in.

Using ScriptRunner, you can extend this basic “Hello World” program to perform various advanced actions in Jira. For example, you can create issues, update fields, transition workflows, and more.

One of the excellent features of ScriptRunner is its ability to access all the Jira APIs and functionality. This allows you to enhance your Jira experience by automating repetitive tasks, generating reports, or creating custom workflows.

Furthermore, ScriptRunner also provides extensive documentation and a helpful community to support you on your scripting journey. You can find example scripts, guides, and tutorials to help you understand and utilize the full potential of ScriptRunner.

In conclusion, ScriptRunner is a fantastic plugin for Jira that allows you to leverage the power of Groovy scripting to automate tasks and customize your Jira workflows. By starting with a simple “Hello World” program, you can gradually explore and discover the endless possibilities this plugin offers. So, get started with ScriptRunner today and unlock the true potential of Jira with your scripting skills.


Please enter your comment!
Please enter your name here