Groovy Script as a Service


I'm having a few issues getting a Groovy script to execute as a timed job in the Services panel. The script seems to be sound, and will quite happily execute using the script console both as an inline script and as a file from the file system. 

I've set the service up as:

Class: com.onresolve.jira.groovy.GroovyService

Name: TestScript

with a schedule of every 15 minutes. 

When setting the path, I've tried it as an absolute path from the root, and as a relative path in the scripts folder, both of which work in the script console. The script has a .groovy extension

The logs don't report any errors in finding the files, running the script etc. but at the same time, the issue that is meant to be created by the script isn't created in JIRA. 

Is there anything I should be doing to my script in order to make it work differently under the service job? I'm assuming that it's finding the script given the lack of complaining that the file is missing in the logs, but that's just an assumption. 

Any help would be greatly appreciated :)


2 answers

Hey dave!

Would you mind sharing your service script with me so that I might take a look and see if there are any issues?

Additionally, it may help to see a screenshot or two of your service configuration in JIRA.

Thanks!                                                                                                     Aidan

Hi Aidan, 

Please find the details below


Hi Aidan,

Thanks for getting back to me, I'm sure I'm missing something stupid but can't see the wood for the trees. The config for the service is:


The overview is:


 and the code is:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.project.Project;

def createIssue(String createdBy, String projKey, String issueSummary, String reportedBy, String issueType = "12345") {
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(createdBy);
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();
Project curPrj = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projKey)
if(curPrj == null)
return "no project"


IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(user, inputParameters);


IssueService.IssueResult createResult = issueService.create(user, createValidationResult);
return "Error in Issue Creation"
return "Not creating invalid issue"

createIssue("testuser1", "TST", "This is a another test issue", "testuser2");

 Hoefully you can spot something I'm missing. 

Thanks again


Hey again Dave!

Sorry for my super belated reply :(

Looking at your script and config, it's hard to get a read on the problem. But I've talked with a colleague and we have a couple of ideas:

  1. It looks like you are missing a package declaration at the top of your script. Check to make sure that this is intentional. If the script is within a package that isn't specified, this could be a reason for the script to fail, as it will not run.
  2. As stated in this community question ===> <=== you need to set the "logged in user." In the context of a Service, the logged in user is anonymous. The problem here may be that, since JIRA authenticates the use of API against the logged in user, the anonymitiy of said user makes it so that statements like:
    ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey(createdBy);
    aren't working properly. To fix this, look to the community question that I linked above.
  3. You may be getting errors and you don't know it. In your script, you are using return statements instead of logging statements for your errors, so you may be getting one but they aren't showing up in the logs. Instead of the return statements, do:
    log.error("Error in Issue Creation")

Once you've checked these things and have made the appropriate changes, look try running the service again and checking your logs.

Let me know what you find!

Cheers,                                                                                                           Aidan

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


267 views 0 7
Read article

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