Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,367,221
Community Members
 
Community Events
168
Community Groups

execute python script from custom dialog box using scriptrunner

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

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

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
DEPLOYMENT TYPE
SERVER
TAGS

Atlassian Community Events