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,299,230
Community Members
 
Community Events
165
Community Groups

Is it possible to execute a jira scriptrunner script from outside jira?

I have a script in scriptrunner in Jira, that I can execute in the console correctly.

 

Is it possible to somehow execute that script from outside Jira, for example from Bamboo?

1 answer

Hi @Ricardo Martinez yeah you can execute scripts which are stored on Jira Server via REST API. It is described here:

https://scriptrunner.adaptavist.com/5.6.8/jira/builtin-scripts.html

In section Executing Script Console Scripts Remotely

Thanks Martin.

Its exactly what I was looking for.

 

And i have it working now!  ;)
like this:

curl -u admin:admin -X POST "http://<jira>/jira/rest/scriptrunner/latest/user/exec/" -H "X-Atlassian-token: no-check" -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "Accept: application/json" --data-urlencode "scriptFile=foo/bar.groovy"


Do you know how can I send an argument to the script with the previous command?

Hi @Ricardo Martinez , sorry. I do not know how to pass parameters :(

You can send a "body" for a POST call using standard REST API formatting. Inside the scriptrunner script you then need to process it. You should use a standard JSON format so it's straight forward. The body is only available for POST calls. 

You need to include:

import groovy.transform.BaseScript
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
import org.codehaus.jackson.map.ObjectMapper

and then in your REST endpoint:

yourrestapi( httpMethod: "POST",
groups: ["jira-administrators"] ) {

MultivaluedMap queryParams, String body ->

String jsonString = body
JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(jsonString)
String jsonPARM1 = parsedJson.get("PARM1")")

etc...

where your JSON body would be something like {"PARM1":"parm1 value"} and any other parameters you need. You can even pass arrays and retrieve inside the groovy script as lists with:


List jsonLIST= parsedJson.get("LIST")

and reference as

jsonLIST[i] 

or

jsonLIST.each { ... }

Suggest an answer

Log in or Sign up to answer
TAGS

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