Forums

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

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

Ricardo Martinez
Contributor
May 20, 2021

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

0 votes
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
May 20, 2021

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

Ricardo Martinez
Contributor
May 20, 2021 edited

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?

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
May 23, 2021

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

Tim Thompson March 9, 2022

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
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