Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Troubleshooting Running a Groovy Script as a Service (Scriptrunner) Edited

I'm trying to figure out what I'm doing wrong to get a Scriptrunner groovy script running as a service, after reviewing posts such as these:

https://community.atlassian.com/t5/Answers-Developer-Questions/Unable-to-run-a-groovy-script-as-a-service-using-script-runner/qaq-p/503808 

https://scriptrunner.adaptavist.com/5.5.5/jira/services.html

For context, I'm running Jira Server 7.10.2 on a Linux box with the Scriptrunner version 5.5.5 plugin.

I've created a simple sanity-check script as follows, ensuring to set the logged in user to an admin user (obfuscated):

/*
This script is here for sanity-checking setting up a Jira service to execute
a groovy script
*/

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.*;

ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("******");
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user);

Logger log = Logger.getLogger("com.foo.groovyScripts");
message = "This is a test confirming groovy scripts run in Jira as a Service."
log.debug(message)
log.info(message)
log.warn(message)
log.error(message)

I can copy-paste this script and run it successfully from the Script Console, and I can see the output in the logs when I tail the atlassian-jira logs.

So, I've created a script in the scripts directory and have made sure it has both read and execute permissions, and that it is owned by the service account and that the file actually contains the script:

[foo@ip-123-456-789-321 scripts]# pwd
/path/to/jira/home/scripts

[foo@ip-123-456-789-321 scripts]# ls -la
...
-rwxr-xr-x 1 jira jira 620 Jun 10 12:18 test-service.groovy

[foo@ip-123-456-789-321 scripts]# cat test-service.groovy
/*
This script is here for sanity-checking setting up a Jira service to execute
a groovy script
*/

import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.*;

ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("*****");
ComponentAccessor.getJiraAuthenticationContext().setLoggedInUser(user);

Logger log = Logger.getLogger("com.foo.groovyScripts");
message = "This is a test confirming groovy scripts run in Jira as a Service."
log.debug(message)
log.info(message)
log.warn(message)
log.error(message)

I've also setup the script in Jira with the class:

com.onresolve.jira.groovy.GroovyService 

and cron expression (should run every 5 seconds):

 0/5 0/1 0 ? * * * 

And finally I've tried both the absolute and relative-to-script-roots paths:

/path/to/jira/home/scripts/test-service.groovy

test-service.groovy

However, the script just won't run. (I don't see anything in the logs)

In addition to my own package (com.foo.groovyScripts), I've also tried enabling logging on com.atlassian.jira.service, com.atlassian.jira.services, and com.onresolve.jira.groovy to see if I could find any information at the DEBUG level. I can see that some beans are being instantiated and script registered, however I'm seeing no error information.

2019-06-10 ... /secure/admin/EditService.jspa [c.o.jira.groovy.GroovyService] groovyService.init : input-file=/path/to/jira/home/scripts/test-service.groovy
2019-06-10 ... /secure/admin/ViewServices!default.jspa [c.o.j.groovy.groovyrunner.spring] BeforeInstantiation [bean=com.onresolve.jira.groovy.GroovyService, type=com.onresolve.jira.groovy.GroovyService]
2019-06-10 ... /secure/admin/ViewServices!default.jspa [c.o.j.groovy.groovyrunner.spring] AfterInitialisation [bean=com.onresolve.jira.groovy.GroovyService, type=com.onresolve.jira.groovy.GroovyService]

Is there anything else I can do to figure out why this is not running?

I'm not sure if there is something simple I'm missing (I've checked permissions on the files, user executing the script, existence of the file, content of the file, log levels, and service settings), or if this is a degrade/bug.

1 answer

1 accepted

0 votes
Answer accepted

Can you include screenshots of your service configuration screens?

Hover over the edit link... and grab the id in the url

Then check the scheduler details screen. Switch to Jobs tab and search for the id.

Then check if it's even registered. What the last run duration is and click show more to view the details and include them here if available.

We can go from there.

Based on what you're explaining, you shouldn't even need to set the logged in user, that really just depends on the tasks you need to do.

Thanks for your help, Peter! I forgot that tab existed, it was helpful in verifying that the script was in-fact registered and...running.

 

But I did find the problem with some help from ScriptRunner support, to my embarrassment: the cron expression. 

 

I was using https://www.freeformatter.com/cron-expression-generator-quartz.html and the expression it generated (0 * 0 ? * * *) wasn't correct. I was able to confirm the script was running every minute--but at hour 0 only (midnight). 

I recommend not using that one...

The person that helped me pointed me to http://www.cronmaker.com/, which actually provided the correct expression to run once per minute (0 0/1 * 1/1 * ? *).

Like Matthew Clark likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

75 views 0 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you