You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jira自动化规则Groovy脚本报错:issueLinkType未定义

修复Jira自动化脚本中issueLinkType未定义的错误

错误原因

报错groovy.lang.MissingPropertyException: No such property: issueLinkType for class: SuperFeature.rest_superFeatureGenerator,核心原因是代码调用issueLinkManager.createIssueLink()时,使用了未初始化的issueLinkType和sequence变量;同时循环创建关联问题的逻辑存在漏洞——重复复用同一个MutableIssue实例,最终只会生成一个问题。

修复步骤

  1. 初始化IssueLinkType对象:通过IssueLinkTypeManager获取你实际需要的问题关联类型(按名称或ID均可)
  2. 定义sequence变量:该参数表示关联的顺序,常规场景设置为1即可
  3. 修正循环创建问题逻辑:将MutableIssue实例的创建移至循环内部,确保每个组件对应一个独立的新问题

修改后的完整代码

package SuperFeature 

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent
import com.atlassian.jira.event.issue.link.IssueLinkDeletedEvent
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.issue.link.IssueLinkType


def log = Logger.getLogger('atlassian-jira.log')

log.warn("MOUNA: ")

log.warn("MOUNA COMPONENT NUMBERS : "+ issue.getComponents().size())

List<String> componentList = new ArrayList<String>()
def authenticationContext = ComponentAccessor.jiraAuthenticationContext


if (issue.getComponents().size()==0){
    log.warn("MOUNA CAMELIA COMPONENTS")
    issue.update {
    String text= "Issue does not have any components\n"
    setCustomFieldValue('Execution Summary', text)
    }
}else if(issue.getFixVersions().size()==0){
            log.warn("MOUNA CAMELIA VERSIONS")
            issue.update {
                String text= "Issue does not have any fix versions\n"
                setCustomFieldValue('Execution Summary', text)
                }

    
}else{
            log.warn("MOUNA CAMELIA ELSE")

        int componentSize=issue.getComponents().size()

        for(ProjectComponent component : issue.getComponents()) {
                componentList.add(component.getName())
        }

        issue.update {
            String text= "The super feature "+issue+" will be split into "+componentSize+
            " features, one for each component:\n"

            for(String component: componentList){
                text = text +"-"+ component+"\n"; 
            }
            setCustomFieldValue('Execution Summary', text)

}

// 获取必要的管理器实例
def issueManager = ComponentAccessor.issueManager
def issueFactory = ComponentAccessor.issueFactory
def issueLinkManager = ComponentAccessor.issueLinkManager
def userManager = ComponentAccessor.userManager
def issueLinkTypeManager = ComponentAccessor.getComponent(IssueLinkTypeManager)

// 初始化问题关联类型:替换为你实际使用的关联类型名称,例如"Relates to"或"Parent/Child"
def issueLinkType = issueLinkTypeManager.getIssueLinkTypeByName("Relates to")
// 定义关联顺序值
def sequence = 1
// 获取当前执行脚本的用户
def currentUser = authenticationContext.getLoggedInUser()

for(String component: componentList){
    // 每次循环创建新的问题实例,确保每个组件对应独立问题
    MutableIssue newIssue= issueFactory.issue
    
    newIssue.setProjectObject(issue.getProjectObject())
    newIssue.setSummary("MOUNA CAMELIA - ${component}")
    newIssue.issueTypeId= 19
    newIssue.setAssignee(userManager.getUserByName("mouh"))
    newIssue.setDescription(issue.getDescription())
    
    // 保存新创建的问题到Jira系统
    def createdIssue = issueManager.createIssueObject(currentUser, newIssue)
    
    log.warn("MOUNA CAMELIA component"+ component +" NEW ISSUE "+ createdIssue)
    log.warn("MOUNA CAMELIA Component "+ component+" issue.getId() "+ issue.getId()+" issueLinkType "+issueLinkType+" sequence "+ sequence)                
    
    // 创建问题关联:注意传入的是关联类型ID而非对象
    issueLinkManager.createIssueLink(issue.getId(), createdIssue.getId(), issueLinkType.id, sequence, currentUser)
}
}

关键修改说明

  • 新增issueLinkTypeManager的获取逻辑,通过getIssueLinkTypeByName获取指定关联类型(请根据你的Jira配置修改关联类型名称)
  • 明确定义sequence变量并设置为常规值1
  • 将MutableIssue实例创建移至循环内部,避免重复复用同一实例
  • 添加issueManager.createIssueObject逻辑,确保新问题实际保存到Jira
  • 修正createIssueLink的参数:传入issueLinkType.id(该方法要求的是关联类型ID而非对象)

内容的提问来源于stack exchange,提问作者منى

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 17:25:05