How to execute Shell script in the Post Functions/Validators

swathi K April 23, 2019

I want to executing a shell script in the post functions and the output obtained from it should be stored in a Text Type custom field.

I have tried using the below script but it did not work. Kindly suggest.

def sout = new StringBuffer(), serr = new StringBuffer()
def proc = 'sh /jira/test.sh'.execute ()
proc.consumeProcessOutput(sout,serr)

String fileContents = new File('jira/out.txt').getText('UTF-8')
return fileContents

1 answer

0 votes
Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 23, 2019

Hi,

I have been using this snippet to execute sh scripts : 

def shCommand = "sh /jira/test.sh"
return = Runtime.getRuntime().exec(shCommand);
int exitCode = return.waitFor()

Let me know how that went.

Antoine

swathi K April 23, 2019

This is not working

Antoine Berry
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 24, 2019

Hi,

You can check this link. I am using method #4 but you can try another one.

Antoine

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events