如何在Groovy中创建工作数组(Scripturner)?(jira/workflow/post-function)

rslzwgfq  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(37)

请告诉我如何使我的代码与Groovy数组(scriptrunner)一起工作我写了代码,它只在获取特定元素(字符串)时工作
我已经试了100次了,但是没有成功...
关于这个主题有一点信息,我正沉浸在对出了什么问题的猜测中。
我的目标:检查一个包含jira中的链接问题的数组的问题类型。
例如,如果数组包含类型为“bug”的链接任务,则返回true
我的代码:

//arrLinkedIssue = issue.getLinkedIssues() //[TENDER-25941, ATL-2925] Result type:ArrayList

def issueManager = ComponentAccessor.issueManager 

issue = issueManager.getIssueObject('TENDER-25941')
issType = issue.get("issuetype").name

if (issType in 'Bug'){
  return issType
}

字符串
谢谢


的数据

nqwrtyyt

nqwrtyyt1#

简单的groovy和一些用于演示目的的mock:

def arrLinkedIssue = ['TENDER-25941', 'ATL-2925']
def mockIssueManagerContent = ['TENDER-25941':[ issuetype:[ name:'Bug' ] ], 'ATL-2925':[ issuetype:[ name:'Feature' ] ]]

//def issueManager = ComponentAccessor.issueManager 
def issueManager = [ getIssueObject:{ mockIssueManagerContent[ it ] } ] // mock issueManager

boolean isBugged = arrLinkedIssue.any{ 'Bug' == issueManager.getIssueObject( it )?.issuetype?.name }

assert isBugged

字符串

9vw9lbht

9vw9lbht2#

在花了很多时间之后,我终于能够弄清楚了。希望这对某人有帮助

arrLinkedIssue = issue.getLinkedIssues() //[TENDER-25941, ATL-2925] Result type:ArrayList

issLi = []
def issueManager = ComponentAccessor.issueManager

for(i in arrLinkedIssue) {

issueLinkKey = issueManager.getIssueObject(i.toString())
issType = issueLinkKey.get("issuetype").name
issLi.add(issType)
} 
//return issLi [Bug, Task]

if('Bug' in issLi){
return false // The task contains a linked task with the task type "Bug" -> Post-function not start!
}
else{ //The task does not have a link task with the task type "Bug" or there is no link at all (null) -> Post-function is launched!

return true
}

字符串

相关问题