Hi
Still new to Groovy - i am wondering if my code is incorrect as my groovy script does not seem to want to execute, i did have it as a script listener but for company purposes it needs to be changed to a service. The only thing i did when i changed it from listener to service was add the JQL search part, looking through it - it all seems to be fine (to the best of my knowledge anyhow). My code is below - (things are named test as to protect company name etc)
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager;
import java.util.logging.Logger
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug("start of code")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)
def cFieldValue = issue.getCustomFieldValue(estField)
log.debug(cFieldValue)
jqlSearch = 'updated ≥ -4w'; // Create the JQL query to perform
theUser = "jira_bot"; // Specify the user that should execute the query if not logged in
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
UserUtil userUtil = ComponentAccessor.getUserUtil();
User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
// If the user isn't specified, then set it to the default script running user
if (!user) {
user = userUtil.getUserObject(theUser);
}
// Set the default list of issues to null just to be safe
List<Issue> issues = null;
// Perform the search as a user and return the result so it can be validated.
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);
Issue issue = event.issue
if(parseResult.isValid()){
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issue.each(){
if ( cFieldValue == 0.0) {
def subject = "${issue.key} has no Estimate"
def body = "https://test.atlassian.net/issue/${issue.key} \n This issue does not have an estimate"
def emailAddr = "test@test.com"
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body.toString());
mailServer.send(email);
log.debug("Mail sent")
}
else {
log.debug("Please make sure that a valid mailServer is configured")
}
}
}
}
else{
log.error("Invalid JQL: " + jqlSearch);
}
Also this is a screenshot of my service i am executing-
Hello,
Did you provide com.onresolve.jira.groovy.GroovyService class from the Service. Are there no logs from your service in the atlassian-jira.log?
Hi Alexey, thanks for the response.
Could you ellaborate on this a bit more for me please
Where are these logs stored as I tried looking for them.
Many thanks
Tyler
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly read this KB to find the log location:
https://confluence.atlassian.com/jirakb/where-are-the-application-server-logs-695240952.html
You can read more about ScriptRunner services here:
https://scriptrunner.adaptavist.com/4.3.0/jira/services.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your second link, I did all of this.(you can see in the screenshots I provided)
I will look at the logs now and see what was outputted if it was.
Thanks again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It is strange. It should work. Make a simpler script with log.error("my script output"). Add it as it is explained in https://scriptrunner.adaptavist.com/4.3.0/jira/services.html and have a look at the logs.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev do you think my file path could be incorrect within my service i set up? please check the screenshot
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Alexey Matveev
I finally managed to find a log input for this
IHNE.run(IHNE.groovy:17) is the following: "
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)"
2018-06-04 23:05:00,010 Caesium-1-2 INFO anonymous no estimate - send email [c.o.jira.groovy.GroovyService] groovyService.run
2018-06-04 23:05:00,127 Caesium-1-2 DEBUG anonymous no estimate - send email [c.onresolve.jira.groovy] start of code
2018-06-04 23:05:00,233 Caesium-1-2 ERROR anonymous no estimate - send email [c.o.jira.groovy.GroovyService] Script service failed: D:\Atlassian\scripts\IHNE.groovy
groovy.lang.MissingPropertyException: No such property: issue for class: IHNE
at IHNE.run(IHNE.groovy:17)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to change the line to:
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401L)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Tyler Brown-Jones I saw you tried to bump the thread, did you see Alexey's suggestion above?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.