Using Scriptrunner to create own log files for deleted issues

Hello,

We want to have a listener on the "Issue Deleted" event that will write into a file the id of the deleted issue. I know th Auditor plugin logs this, but that info can't be accessed from a script so we need to make our own log.

I am playing around and trying this:

import org.apache.log4j.Logger
import org.apache.log4j.Level

File file = new File("test.txt")
file.write "Issue " + event.issue.getKey() + " was deleted"
log.debug("Issue " + event.issue.getKey() + " was deleted " + file.absolutePath)

 It should be simple but the file is not at the location indicated by file.absolutePath. Why can't I find this file? Is there some restriction from Scriptrunner/Groovy for writing to my own files?

Our JIRA is running on Linux and it's inside a Docker container (I've already checked it and the file isn't there either)

1 answer

0 vote
Gaston Valente Community Champion Dec 13, 2017

Cristina,

You can try to save the file relative to JiraHome using 

ComponentAccessor.getComponentOfType(JiraHome.class).getHome()

 You can also use a concrete absolute path but this is less portable

If you use File("log.txt") it will be saved relative to the directory of execution.

Hope it helps

Hi, 

I tried using your solution but i get an error from the static code check saying that JiraHome is undeclared. How do I iniatialize it? I couldn't find anything in the API.

Additionally, if I try to specify the absolute path for the file like this:

import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.startup.JiraHomeLocator

 

def create = new File("/opt/ea/DIV_I/IC/IC_001/jira-home/scripts/com/listeners/test.txt").createNewFile()
def file = new File("/opt/ea/DIV_I/IC/IC_001/jira-home/scripts/com/listeners/test.txt")

I get this error:

2017-12-14 01:57:40,099 WARN [common.UserScriptEndpoint]: Script console script failed: java.io.IOException: No such file or directory at java_io_File$createNewFile$10.call(Unknown Source) at Script770.run(Script770.groovy:8)

 If i skip the call to call to createNewFile() I get no error, but same as before no file is at the location that I indicate.

Any ideas?

Thanks,

Cristina

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,308 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot