【问题标题】:return codes for Jira workflow script validatorsJira 工作流脚本验证器的返回码
【发布时间】:2019-02-27 05:15:50
【问题描述】:

我正在 Groovy 中编写一个工作流验证器,以在创建案例时根据自定义字段值输入链接两个问题。要求 Jira 问题链接的自定义字段值是唯一的。换句话说,我需要确保只有一个问题具有特定的自定义字段值。如果有多个问题具有输入自定义字段值,则验证应该失败。

我如何返回或返回什么导致工作流验证器失败?

示例代码:

// Set up jqlQueryParser object
jqlQueryParser = ComponentManager.getComponentInstanceOfType(JqlQueryParser.class) as JqlQueryParser
// Form the JQL query
query = jqlQueryParser.parseQuery('<my_jql_query>')
// Set up SearchService object used to query Jira
searchService = componentManager.getSearchService()
// Run the query to get all issues with Article number that match input 
results = searchService.search(componentManager.getJiraAuthenticationContext().getUser(), query, PagerFilter.getUnlimitedFilter())
// Throw a FATAL level log statement because we should never have more than one case associated with a given KB article
if (results.getIssues().size() > 1) {
    for (r in results.getIssues()) {
        log.fatal('Custom field has more than one Jira ssue associated with it. ' + r.getKey() + ' is one of the offending issues')
    }
    return "?????"
}

// Create link from new Improvement to parent issue
for (r in results) {
    IssueLinkManager.createIssueLink(issue.getId(), r.getId(), 10201, 1, getJiraAuthenticationContext().getUser())
}

【问题讨论】:

    标签: groovy jira


    【解决方案1】:

    尝试类似的东西

    import com.opensymphony.workflow.InvalidInputException
    invalidInputException = new InvalidInputException("Validation failure")
    

    这是基于groovy script runner。如果它不适合您,我建议您使用某种框架来简化脚本编写,我喜欢使用 groovy script runnerJira Scripting SuiteBehaviours Plugin .所有这些都确实使脚本编写更容易、更直观。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2016-05-14
      • 2011-06-08
      • 1970-01-01
      • 2023-03-09
      相关资源
      最近更新 更多