Hello,
We run groovy post function script which should create sub-task when new fix version is created or new bus is cretaed. It worked fine on JIRA4.3 installation and now JIRA is updated to 5.0. Script was modified a little bit and now subtask is created when new issue is created (even some errors can be found in the log), but adding new fix version does not create new sub task. The errors in the log are (the full log is attached (fixversion_added.log) )
2012-05-10 10:28:01,102 http-80-2 ERROR admin 628x112x1 19x9h8t 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyRunner] The script failed : javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: log for class: createBranchFixSubTasks
2012-05-10 10:28:01,102 http-80-2 ERROR admin 628x112x1 19x9h8t 10.161.201.37 /secure/CommentAssignIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: log for class: createBranchFixSubTasks
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117)
The script is
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.MutableIssue import com.atlassian.crowd.embedded.api.User import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.workflow.WorkflowTransitionUtil import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl import com.atlassian.jira.util.JiraUtils import com.atlassian.jira.util.ImportUtils class createBranchFixSubTasks { def componentManager def issueFactory def authContext def issueManager def subtaskManager def projectManager def createBranchFixSubTasks(){ } def versionIsContainedIn(version, versions) { for (ver in versions) { if (ver.getName() == version.getName()) { log.warn "Found version: " + versions.getName() return true } } return false } def issueHasFixTaskForBranch(branch, issue) { for (subtask in issue.getSubTaskObjects()) { if (subtask.getIssueTypeObject().getName() == "Branch fix" && versionIsContainedIn(branch, subtask.getFixVersions())) { log.warn "Fix issue already created for version: " + branch.getName() return true } } return false } def createFixTask(fixTo, forIssue) { def parentSecurityLevel = forIssue.getSecurityLevelId() assert (parentSecurityLevel != null) def subtask = issueFactory.getIssue() subtask.setProject(projectManager.getProject(forIssue.getProjectObject().getId())) subtask.setSecurityLevelId(parentSecurityLevel) for (issuetype in subtaskManager.getSubTaskIssueTypeObjects() ) { if (issuetype.getName() == 'Branch fix') { //log.warn("Setting issue type to: " + issuetype.name) subtask.setIssueTypeObject(issuetype) } } // def issuetype = subtaskManager.getSubTaskIssueType('Branch fix') //log.warn("Setting issue type to: " + issuetype.name) //subtask.setIssueType(issuetype) subtask.setFixVersions([fixTo]) subtask.setSummary(forIssue.getSummary()) subtask.setAssignee(forIssue.getAssignee()) subtask.setReporter(forIssue.getReporterUser()) //log.warn "Creating issues: " + subtask.toString() + " by " + authContext.getUser() com.atlassian.crowd.embedded.api.User user = authContext.getUser() def subTaskObject = issueManager.createIssueObject(user, subtask) subtaskManager.createSubTaskIssueLink(forIssue, subtask, user) //log.warn "Created branch fix issue for: " + fixTo.getName() } def public processIssue(com.atlassian.jira.issue.MutableIssue issue){ componentManager = ComponentManager.getInstance() issueFactory = componentManager.getIssueFactory() authContext = componentManager.getJiraAuthenticationContext() issueManager = componentManager.getIssueManager() subtaskManager = componentManager.getSubTaskManager() projectManager = componentManager.getProjectManager() def wasIndexing = ImportUtils.indexIssues ImportUtils.indexIssues = true def parentIssueNeedsUpdate = false for (fixTo in issue.getFixVersions()) { if (!issueHasFixTaskForBranch(fixTo, issue)) { createFixTask(fixTo, issue) parentIssueNeedsUpdate = true } } if (parentIssueNeedsUpdate) { issueManager.updateIssue(authContext.getUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false) } ImportUtils.indexIssues = wasIndexing } } creator = new createBranchFixSubTasks() creator.processIssue(issue)
could you please tell what might be wrong here?
Thank you in advance.
Cheers, Georgiy
It's telling you what's wrong I think... "log" is not defined. That variable should be available in the script, but it won't be in the class that you defined in the script.
So you can pass it in in a constructor for the "createBranch..." class, or add to the inner class:
Category log = Category.getInstance(createBranchFixSubTasks.class)
(import import org.apache.log4j.Category).
BTW I'm not aware of anything in this area that would have broken between 4 and 5 - are you sure you didn't refactor the script?
Thank you for pointing me that "log" causes the problem.
As the "log" is used for debuging purpose only then I solved this problem by removing all lines with "log
.warn
" and problem disappeared.
The script was refactored because original one stopped working since we switched form JIRA4.3 to JIRA5.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, I guess it was "com.atlassian.crowd.embedded.api.User user".
If you had just used "def user", ie dynamic not static typing it would have worked in 4.3 and 5.0.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.