Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Can ScriptRunner run Python script on server?

Using ScriptRunner's Custom Scheduled Job (plugins/servlet/scriptrunner/admin/jobs), I'd like to specify a Python script to run.

Does ScriptRunner only run Groovy scripts ?

 

2 answers

1 accepted

0 votes
Answer accepted

Scriptrunner I think used to be called "groovy runner" ... so really it's only groovy/java.

But a groovy script can execute a command on the server just like you would from the command line.

So if you want to run a python script, you can do something like this:

def sout = new StringBuilder()
def serr = new StringBuilder()
def cmd = "/path/to/python/script.py"
def proc = cmd.execute()
proc.consumeProcessOutput(sout,serr)
proc.waitForOKill(30000)
if(serr){
log.error "Error exeucting python script with standard error output: \n $serr"
log.debug "Erroring Python script had standard output:\n $sout
} else {
log.debug "Python script executed succesfully with standard output:\n $sout"
}

Thank you @Peter-Dave Sheehan , that makes total sense. I will try this, but haven't yet. Nonetheless, you answered my question and I will mark it as Answered.

How to catch error in python script? Above code does  run the script but not failing the post function even if the python script failed. Can you please suggest any way to fail post function with example please.

There is no exit/failure path (that I'm aware of ) for any post-function script.

That's what validators are for.

The best you can do is consume the standard error output from the command execution and let the user know.

Maybe you need to split your python script in 2, a validation script and an execution script.

Executed the validation script from a custom script validator, if it fails, throw an exception and stop the transition. If it passes, run the execution script as a postfunction to perform whatever action you need it to.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Learn how to request and manage app requests in the Marketplace

G’day everyone! Super exciting news coming from the Marketplace. We have now fully rolled out the ability for end-users to submit app requests to admins directly from within the product! No longer ...

62 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you