Forums

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

How do I run a groovy script at startup?

Sammo Gabay March 22, 2018

I was wondering how to run a script using the ScriptRunner plugin when my Jira instance starts. Our custom scripts need some initialization to run correctly, and the current process is for the system admin to go run a startup script manually using the console.

I’m curious if there is an event I can listen for or part of the ScriptRunner API I can tap into. I did find that ScriptRunnerImpl does feature a runScriptsAtStartup method, but I am not sure what this does or if I can use it. My current best idea is to add a delay to the startup shell script after the jira command and then call a custom REST endpoint using curl, hoping that Jira is fully initialized when the call is made.

Part of me wonders if it’s time to develop a full-blown plugin.

@Jamie Echlin _ScriptRunner - The Adaptavist Group_

1 answer

1 accepted

0 votes
Answer accepted
Jamie Echlin _ScriptRunner - The Adaptavist Group_
Atlassian Partner
March 22, 2018

If you put the script(s) in the package: "startup", it will be run run at jira startup. Similarly there is also pluginstartup, which runs on plugin enablement.... sounds like you want the former.

Sammo Gabay March 23, 2018

Thanks @Jamie Echlin _ScriptRunner - The Adaptavist Group_, that step worked and the script ran perfectly!

Now, part of the script initializes plugin.rest.scripts.package. Is there a way to call the custom rest scanner using groovy alone to lookup and add the REST endpoints (i.e. not with a request to /rest/scriptrunner/latest/custom/customadmin/scancustom, but with a method call?)

Thanks,
Sammo

Jamie Echlin _ScriptRunner - The Adaptavist Group_
Atlassian Partner
March 25, 2018

Not really sure why you need this... the "scan" function is only necessary if you add (or remove) a file under the script root that contains new rest endpoints, and you don't want to restart.

Restarting always does a scan... can you be more specific about what you are trying to do?

Sammo Gabay March 25, 2018

So when I set the system property “plugin.rest.scripts.package” to bar.foo.jira.rest (in my startup groovy script) and do the scan, it finds the endpoints. Will it remember them by itself when Jira restarts? How does it know to scan that package?

Jamie Echlin _ScriptRunner - The Adaptavist Group_
Atlassian Partner
March 29, 2018

No, I don't think it will remember them. The usual way of setting a system property is in the jira startup or setenv files, add -Dpropname=value.

https://confluence.atlassian.com/adminjiraserver071/setting-properties-and-options-on-startup-802593108.html

Your way would work but seems unnecessary, best to set it in the same place all your other system properties are set.

Sammo Gabay April 2, 2018

Thanks, this works great!

Dan C
Contributor
April 10, 2023

Hello @Jamie Echlin _ScriptRunner - The Adaptavist Group_ and @Sammo Gabay  - I'm also trying to get a script to run on Jira startup.

 

I'm not 100% sure what you meant by adding the script to the "startup" package.

 

I placed the script in a folder named "startup" in script editor, and added "package startup" at the top of the script.

When restarting Jira, the script did not run.

 

Am I missing something?

 

Thanks,

Dan

Suggest an answer

Log in or Sign up to answer