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?
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ricardo Martinez , sorry. I do not know how to pass parameters :(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 { ... }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.