execute python script from custom dialog box using scriptrunner

Omar Morales August 23, 2022

Hi all,

I have a custom dialog box I created using a scriptrunner web fragment and custom REST endpoint.

On this dialog box I have a button that I would like to fire off a python script that lives on the jira server.  I'm not really sure how I could go about doing this.

My initial thought was have the button point to another custom REST endpoint where the the script would be executed. Is this at all possible?

I'm open to feedback and new ideas on how I can go about doing this.

Thank you

1 answer

2 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 24, 2022

Hi @Omar Morales

You could try something like this:-

import java.io.FileReader

def file = new File('/home/ram/Downloads/test.py')

def command = "python3 ${file.absoluteFile}"

def proc = command.execute()

proc.waitForOrKill(1000)

log.warn "return code: ${ proc.exitValue()}"

log.warn "stderr: ${proc.err.text}"

log.warn "stdout: ${proc.in.text}"

def fileReader = new FileReader("/home/ram/Downloads/readme.txt")

fileReader.readLines().each {

log.warn it

}

I have tested this to execute a very basic python code, i.e. to update a text file using the ScriptRunner console, and it is working.

Below is a screenshot of the configuration and output for your reference:-

image1.png

You should be able to use a similar approach on the web-fragment.

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 28, 2022

Hi @Omar Morales

Does the solution I provided help to solve your question?

If yes, please accept the answer.

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer