Where do I drop the CSV file so my ScriptRunner script can see it?

I am writing a script that needs to read some data from a csv file.  This is the line that I want to use to access the file and store the data.

InputStream inputFile = getClass().classLoader.getResourceAsStream("projectToEpicMap.csv")
String[] lines = inputFile.text.split('\n')
List<String[]> rows = lines.collect {
it.split(',')
}

Where do I have to put my csv file so this line will be able to access it?  At the moment all I am receiving is a NullPointerException.  Right now I have the csv file in this location.

<JIRA Install Directory>\atlassian-jira\WEB-INF\lib

1 answer

1 accepted

This widget could not be displayed.

Hi Mark,

I made a slight change to your script. I have used "File" instead of using the classloader as it's a simpler approach. I also added an if statement to check for the presence of the file, so that you get more useful output than before in case the file is not found.

File file = new File("<path_to_jira_home>/files/test.csv") // <-- Change this to your path...

if (file.exists() && file.isFile()) {
String[] lines = file.text.split('\n')
List<String[]> rows = lines.collect {
it.split(',')
}
} else {
"No file found at that location..."
}

A couple of points on this:

1. Create a new directory in your JIRA_HOME directory for storing these kinds of files.

2. You need to provide an absolute path to the files on the server. I don't believe this will work with relative paths.

You should be able to run this script in your "Script Console" as-is to test. I would always recommend against carrying out this kind of development in your production JIRA instance. It is always best to test these changes in a pre-production instance first :-)

I hope this helps!

Steve

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in Statuspage

What are your best incident management tips and stories? #HugOps

 👋Community members! Downtime happens. And great incident response takes a village. Teams like Support, Dev, SRE, Ops, IT, and Marketing have to come together to resolve the problem while keep...

70 views 2 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you