postfunctions
August 22, 2019

The Script Series, Volume 4: 5 Simple Scripts to Automate Issues in Jira

SC
Sophie Conner 4 minute read
In Volume 4, we will show you how our ‘Getting Started with Jira issues’ collection will help you save time and effort when automating issues in Jira. As there’s so many useful scripts in this collection, we have split this collection into two separate blog posts, so you can find out how to get the most out of each script.

If you’re new around here, it’s time for a quick recap. Check out our other blog posts in The Script Series below to find out more:

 

  • In Volume 1, we explored how our ‘Users and Groups in Jira’ collection helps make bulk actions easy, such as updating all users in a group at once.
  • Volume 2 featured our ‘Working with Dates and Times’ collection, which lets you automate and extend your built-in Jira workflows.   
  • In Volume 3, we collaborated with our Partner, ALM Works, to help you utilise the power of ScriptRunner and Structure together. This collection provides ways to automate, extend and customise your structures in Jira.

This collection is a great place to start if you’re new to ScriptRunner for Jira Server and Data Center, or looking for some more basic functionalities. It contains nine scripts to help you extract information from Jira. Once you’ve got the hang of ScriptRunner, you can build on these scripts to create complex workflows and automate your administration. 

ScriptRunner Script: Automate the creation of an Issue in Jira. 

This script saves you the time and effort of creating issues manually. You can add this script to anywhere in Jira that allows you to add a custom script e.g. listeners, workflow functions, REST Endpoints. You can either add this script as a standalone script, or as part of a larger script to create some serious automations! 

Example 
I am a Product Manager and I need to create a number of issues weekly for different departments. For example, I need marketing to provide me with their weekly analytics report for the product campaigns we have running. Previously, I was having to spend time every week manually assigning these issues. However, this script means that the issues are scheduled automatically to be created weekly.

ScriptRunner Script: Automate your Project creation in Jira 

One of the most used day-to-day functions in Jira is creating a project, which is a collection of issues in various stages. This script works similarly to the ‘Create an issue in Jira’ script, it allows you to automate the creation of projects, for example in a workflow post function, a REST Endpoint or listener.

ScriptRunner Script: Clone issues or parts of issues 

When cloning an issue, you will be able to clone attachments, subtasks and custom fields with this script. To make it easier to track which issues have been cloned, the newly created issue is linked to the source issue with a 'Clones' issue link. 

You might want to clone an issue if it contains in-depth details and you need a copy of it, or you want to split the workload for an issue. It may be necessary for you to clone an issue when an incident has been fixed and you need to file a Root Cause Analysis (RCA) ticket in another project.

 Screenshot 2019 08 16 at 14.58.47


Screenshot 2019 08 16 at 18.58.53

When cloning the JRA-1 issue, you will see “is cloned by” issue link to the newly created JRA-5 issue.

ScriptRunner Script: Limit your behaviours to specific screens in Jira

A behaviour defines how fields behave for issues in a given project or issue context. Screens allow you to change the displayed fields when creating an issue, editing an issue or transitioning a workflow. This script allows you to execute a specific behaviour logic inside a specific issue screen, such as a workflow transition. 

Example
I work in Product Support and customers often report bugs. When transitioning these issues from one state to another, such as ‘open’ to ‘in progress’ there needs to be a mandatory ‘affects version’ field. I can use this behaviour script to define that this field will be mandatory in these specific transitions. 

ScriptRunner Script: Easily copy your issues to a separate project. 

This snippet shows you how to copy an issue from one project to another. This allows you to either copy the entire issue or the parts of the issue you need. 

Example
My team and I have multiple projects in Jira, there’s a main project and several client projects which each have their own product owners and dashboards. Issues are created in the main project, however, one of my colleagues found the same issue in their client project. So, they use this snippet to copy this issue over to their project.


What’s Next?

Now you’ve got some of the Jira Issue basics down, keep an eye out for Section 2 of this blog post. We’ll be showing you how to comment on a Jira Service Desk ticket in Groovy, update the value of a custom field using a Listener, and more! 
 

SC
Sophie Conner Product Marketing Associate