Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,555,382
Community Members
 
Community Events
184
Community Groups

How do I run a groovy script at startup?

Edited

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Mar 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.

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Mar 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?

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_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Mar 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.

Thanks, this works great!

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