How can I remotely trigger a groovy script on my Jira Server?

I want to provide a mechanim to automate the addition of new options to a select list in our Jira system. I have written a groovy script that does all the heavy lifting and uses the JIRA API to add the provided Options to the select list.

Using the ScriptRunner Script Console, I can run my script and have verified the functionality is correct. The final missing link is finding a way to remotely trigger/execute the groovy script without having to rely on being logged into the Jira GUI.

Does anyone know of a curl/wget/anything-based solution that would allow me to populate the "Script File Path" field on the groovyRunner Script Console page and then trigger the "Run" button? I've been scouring the interwebs for an example of someone doing this, but have come up shy.


2 answers

1 accepted

1 votes

Have you got chrome? If you press f12, run the script from the UI, and look at the network tab. Right-click on the request, there is an option "copy as curl".

Remove all the cookie crap and other stuff and you have what you want, although you will probably want to add "--user username:password" for http basic authn.

Thanks for the reply Jamie. Going to give this a try tonight and will update then.

Worked beautifully Jamie, thank you very much.

For the benefit of others, here's an example of a Windows batch file for triggering a Script Console script remotely:

@echo off

rem Script to run a Jira script on the ScriptRunner Console remotely.
set USERNAME=admin
set PASSWORD=secret
set DASHBOARD_URL=http://localhost:8080/secure/Dashboard.jspa
set SCRIPT_CONSOLE_URL=http://localhost:8080/secure/admin/groovy/GroovyRunner.jspa
set COOKIE_FILE=jiracoookie
set SCRIPT_TO_RUN=C:\helloWorld.groovy

"C:\Program Files\cURL\bin\curl.exe" -u %USERNAME%:%PASSWORD% --cookie-jar %COOKIE_FILE% --output output1.txt %DASHBOARD_URL%
"C:\Program Files\cURL\bin\curl.exe" --cookie %COOKIE_FILE% --header "X-Atlassian-Token: no-check" --data "filename=%SCRIPT_TO_RUN%" --data "Run+now=Run+now" --output output2.txt %SCRIPT_CONSOLE_URL%

It helped a lot Jamie smile 

I changed the cURL a little bit and requested the script from directory. scriptFile=/var/..........clear.groovy"

I would like to run the code but each time I have different variables (dynamic data). Such as posting with different issuekeys. Is it possible ? 

Tansu, I have found that the best way to accomplish what you're trying to do is to create a custom Built-In script that sits along side the ones that are bundled/provided by Jamie. These scripts can have input parameters, and can be tested locally from the "Built-in Scripts" console. When you're satisfied everything works, you can then trigger a curl request to populate the script form, sending as input your dynamic parameters. This amounts to the same concept described above, only you use the Build-in Scripts interface rather than the Script Console interface. Hope that helps.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,867 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot