Forums

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

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 Champion
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 Champion
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
DEPLOYMENT TYPE
SERVER
TAGS
atlassian, jira cloud certification, managing jira projects, jira project administration, jira cloud exam, atlassian certification, agile project management, jira workflows, jira permissions, jira training, jira cloud skills, atlassian learning

Become a Certified Jira Service Project Expert 🦸🏻‍♂️

Validate your expertise in managing Jira Service Projects for Cloud. Master configuration, optimize workflows, and manage users seamlessly. Earn global 🗺️ recognition and advance your career as a trusted Jira Service management expert.

Get Certified! ✍️
AUG Leaders

Atlassian Community Events