如何使用scriptrunner从JIRA问题中删除组件?

时间:2016-09-15 21:00:31

标签: groovy jira

我正在尝试通过Post函数中的ScriptRunner从JIRA问题中删除组件。我尝试以不同的方式做到这一点,但不适用它:

Collection<GenericValue> col =  issue.componentObjects.asCollection()
log.debug logPref + "Deleting: " + issue.componentObjects.removeAll(col)
log.debug logPref + "Deleting: " + col.removeAll([null])

第一行返回true,第二行删除false,但无论如何组件都在它们的位置。 还尝试过:

import com.atlassian.jira.bc.project.component.ProjectComponentManager
import com.atlassian.jira.component.ComponentAccessor
def projectComponentManager = ComponentAccessor.getComponent(ProjectComponentManager)
projectComponentManager.updateIssueProjectComponents(issue, [])

但是得到:

No signature of method: com.atlassian.jira.bc.project.component.DefaultProjectComponentManager.updateIssueProjectComponents() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.util.ArrayList) values: [IID-44017, []]

下列的程序:

import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.bc.project.component.ProjectComponentService
import com.atlassian.jira.component.ComponentAccessor



def jiraServiceContext = new JiraServiceContextImpl(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser())
issue.getComponentObjects().each { it ->
    ComponentAccessor.getComponent(ProjectComponentService).deleteComponentForIssues(jiraServiceContext, it.id)
}

挂起我的JIRA实例并抛出:

2016-09-15 14:09:38,727 http-bio-8080-exec-19 WARN viktork 848x207x1 d9pyfm 10.30.0.198 /secure/CommentAssignIssue.jspa [jira.notification.type.UserCFValue] Exception occurred while working out recipients from a custom field value. Returning empty list.
java.lang.IllegalStateException: There is no ID mapped for the user key 'pmo lead'
    at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySetForUserKey(DefaultUserPropertyManager.java:47)
    at com.atlassian.jira.user.DefaultUserPropertyManager.getPropertySet(DefaultUserPropertyManager.java:31)
    at com.atlassian.jira.user.preferences.DefaultUserPreferencesManager.getExtendedPreferences(DefaultUserPreferencesManager.java:28)
    at com.atlassian.jira.notification.NotificationRecipient.getFormatPreference(NotificationRecipient.java:53)
    at com.atlassian.jira.notification.NotificationRecipient.<init>(NotificationRecipient.java:66)

有没有人有工作方法?我的JIRA版本是6.4.7

1 个答案:

答案 0 :(得分:0)

在将任何内容写入DB之前执行post函数:

issue.setComponentObjects([])