Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can i change the layout of the subtask card to show due date in the main issue view?

Jihadul Islam
October 5, 2021

Annotation 2021-10-05 093903.jpg

2 answers

0 votes
Akshay K V
December 7, 2018

Try the following piece of code. This will write to a file in JIRA_HOME directory.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.util.JiraHome

def jiraHome = ComponentAccessor.getComponent(JiraHome)
def file = new File(jiraHome.home, "test.txt") //location JIRA_HOME/test.txt
file.write "Issue " + event.issue.getKey() + " was deleted"
log.debug("Issue " + event.issue.getKey() + " was deleted " + file.absolutePath)

This will create and write to it.

0 votes
Gaston Valente
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 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

Cristina_Abunei
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
December 13, 2017

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

Akshay K V
December 7, 2018

It seems the file does not exist in the mentioned absolute path.

Suggest an answer

Log in or Sign up to answer