Your Guide to Writing Jira Automation Scripts

While Jira includes dozens of automation recipes, sometimes you need something more bespoke. 

Launching one automation with Java or Groovy can take hundreds of lines of flawless syntax—a mountain of code that bars beginners from getting started with automation.

Enter Simple Issue Language (SIL): the backbone on which apps like Power Scripts, Power Database Fields, and Power Actions are built. SIL is a compact scripting language with the power of more complex programming languages. SIL scripts help automate tasks in Jira, make your day more manageable, and overcome the platform’s native limitations so you can craft the Jira instance of your dreams. 

You don’t need years of programming experience to take advantage of SIL—you just need to grasp a few fundamentals to get started. 

Understanding the basics of SIL

In this beginner’s guide, we’ll walk through the basics of SIL so you can learn how to mix and match its “ingredients” to create your own elementary scripts.

Before you get started, here are a few formatting tips you’ll want to keep in mind: 

  1. You might wonder why you see words written out like “dueDate” or “issueType.” SIL uses a formatting style called camelCase—reminiscent of iPhone or MasterCard. 
  2. Semicolons represent the end of a command, telling Jira to go ahead and run that part of the script. 
  3. You can leave comments in a script as you go along. Keep notes to remember your thought process, or provide instruction for fellow team members. Format notes like this to make sure your script doesn’t include your scratchwork when running the code:

/*

Anything written here is a comment.

*/

Just have a quick one-liner to dash down? You can write it beside two slashes like this:

// Keep track of your thoughts.

Ready? Let’s dive into the basics of how to format a SIL script. 

Variables

The different fields in Jira are known as Variables. They’re how you tell Jira what fields you’re looking to interact with. There are dozens of common variables you can use: 

SIL Variables
assignee issueTypeId projectID
attachments key reporter
created labels status
description parent statusID
dueDate parentID summary
environment priority timeSpent
fixVersions priorityID watchers
id project workflowID
issueType

 

SIL Variables come in different types: string, number, boolean, date, and interval. Check out the chart below to see how you can use variables to name other types of data. 

Data type When to use it Example
String Includes text.  string myVariable = “Pepper”’;
Number You don’t have to use quotes around numbers. number myVariable = 10;
Boolean A true/false value. You also do not need to use quotes here. Boolean myVariable = true;
Date Used to represent a date. date myVariable = ‘10/31/2021’
Interval A time interval like 3 days and 12 hours. interval myVariable = ‘3d 12h’;

 

Let’s start with an example: 

We’ll start by asking Jira to set the  summary of a new issue to “New Urgent Support Ticket”. And in addition to that we want any issues assigned to Pepper made a high priority. 

The variables used here are “summary,” “assignee,” and “priority.” Here’s how the script will look like:

summary = “New Urgent Support Ticket”;

 

if(assignee == “Pepper”) {

priority = “High”;

}

Arrays

Arrays contain a list of values that are the same type of data. This is how you can ask Jira to perform an operation on a particular set of data. 

Check out this example:

Let’s create a list of planets and ask Jira to return the third planet on the list. 

Keep in mind, the first value in an array is numbered 0, the second value is numbered 1, and so on. Therefore, to request the planet in the third position, we ask for planet 2. 

string [] planet = {“Jupiter” , “Saturn” , “Uranus” , “Neptune”};

return planet[2];

Structs

Structs are ways to organize a longer list of fields that contain different types of data. In business, one of the most common types is the organization of customer or client data. 

Here’s an example: 

See how you can organize customer details like first name, last name, company, and birthday.

struct businessContact {

string firstName;

string lastName;

string companyName;

string birthday; 

}

Information for your client would populate as:

businessContact newContact;

 

newContact.firstName = “Peggy”;

newContact.lastName = “Carter”;

newContact.companyName = “S.H.I.E.L.D.”;

newContact.birthday = “04/09/1921”;

Operators

Operators are what you need to start blending together multiple values and variables into a more complex script. Find some of the basic operators below: 

 

Data type When to use it Symbol Example
Addition Add numbers or data together. + 5 + 2;

“Let’s ” + “Be ” + “Friends ”;

Subtraction

Multiplication

Division

Perform other math equations.

*

5 – 2;

5 * 2;

5 / 2;

Assign a value to a variable You saw this one in the previous example. = newContact.firstName = “Peggy”;
Equals Tests to find out if two values are equal. == string myVariable = “Pepper”;

myVariable == “Banner”;

 

Let’s revisit our last example:

Let’s say we would like to display this customer’s full name, plus company name. We can use the addition operator. Our ideal format is: 

Name : Peggy Carter, S.H.I.E.L.D.

We’ll do that with this script:

Return (“Name : ” +newContact.firstName

+“ ” +newContact.lastName

+“,”

+“ ” +newContact.companyName);

 

print (“Name : ” +newContact.firstName

+” ”  +newContact.lastName

+”,”

+” ” +newContact.companyName);

Screenshot of Jira script

Conditionals

Conditionals allow you to ask a question of your data. You can test if a certain parameter is true or false, and Jira will run a code based on those conditions. 

Let’s try an example: 

This script will determine if it’s true or false that the PeriodicElement is neon. Then, Jira will decide which message to display. 

string periodicElement = “neon”;

if(periodicElement == “neon”){

print (“Great for storefronts wanting to grab attention of passersby!”);

} else {

print(“Not so great for window signs.”);

}

Routines

Routines make it easy to perform a predefined function. They’re easy ways to remove repetitive work and free up some time from your day. 

Here’s an example of a routine: 

addComment(key, currentUser(), comment text);

This routine will ask Jira to add a comment to the issue with the issue key signed by the current user of that issue.  

addComment(key, currentUser(), “I have executed a transition.”);

GIF of writing a Jira automations script

You’re ready to write your own beginner SIL scripts!

Thanks to SIL, you’re able to harness the power of more robust programming languages without putting in months (or years!) of training. Top Jira admins are taking full advantage of SIL automation tools to reduce the time drain of manual tasks and curate a Jira instance that addresses their unique needs. 

Have questions or need future assistance with your SIL scripts? Connect with our service desk to get your questions answered!



Tagged with:

Categorized in: , , , ,