How to fetch variable value from a local file to use in Automation for Jira

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Third party plugin solution involved

Please be mindful that the information below pertains to a service that is outside of  Atlassian Support Scope. Any effort provided to support issues related to out of scope issues will be on a best-effort, as-is basis by the support engineer.

How to fetch data from a local file to use in automation for Jira

Environment

9.4.6

Solution

This is demonstration of one of the methods to read a variable value from a local file and use it in automation for Jira. There might be other methods to perform the same, or newer capabilities attached to the A4j in later versions, where the need for utilizing third party scripts can be avoided. The overview of the steps that would be performed is as follows

  1. New trigger (ex. Transition of a issue from one status to another).

  2. Run a script action to run the scriptrunner script to read from file and update the description of an test issue (say HOL-1).

  3. Run the lookupissues action to look up the HOL-1 issue to be used in a smart variable.

  4. Assign the smart value from the {{lookupIssues.description}} to a variable.

  5. Use the variable in subsequent components for your use case, such as commenting on the issue with the value read from the file.

(Auto-migrated image: description temporarily unavailable)

Here is the sample script using the scriptrunner to read from a local file and update a test issue in the description field. This local file consists of lines of data of the following format "key : value" . We will be looking for the key 'secret' and read the corresponding 'value' from the file and update the description field of the test issue 'HOL-1'.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import com.atlassian.jira.component.ComponentAccessor //Path to the CSV file by name 'Profile_Data'. final def csvFileFullName = '/Users/svenkatachari/Downloads/Profile_Data' def file = new File(csvFileFullName) def listofkeysAndValues = [] as ArrayList<Map> //The value from the CSV file separated by colon is extracted and added to a List of Maps file.eachLine { def column = it.split(':') def mapInput = [:] as Map mapInput.put('KeyPair', column[0]) mapInput.put('ValuePair', column[1]) listofkeysAndValues.add(mapInput) } def issueManager = ComponentAccessor.issueManager //The key we will look up in the file def KeyCompare = "secret" listofkeysAndValues.each { data -> if (data.get('KeyPair').toString().trim() == KeyCompare.trim()) { // the test issue key to update. Modify this to your own test issue def issueobj = Issues.getByKey('HOL-1') def DescFieldValue = data.get('ValuePair').toString().trim() issueobj.update { description = DescFieldValue.toString() } } }
Updated on March 24, 2025

Still need help?

The Atlassian Community is here for you.