Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return codes for Jira workflow script validators

Tags:

groovy

jira

I'm writing a workflow validator in Groovy to link two issues based on a custom field value input at case creation. It is required that the custom filed value to Jira issue link be unique. In other words, I need to ensure only one issue has a particular custom field value. If there is more than one issue that has the input custom field value, the validation should fail.

How or what do I return to cause a workflow validator to fail?

Example code:

// 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())
}
like image 252
Alex Ellison Avatar asked Dec 01 '25 09:12

Alex Ellison


1 Answers

try something like

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

this is based of the groovy script runner. If it doesn't work for you, i would recommend you using some sort of framework to make scripting easier, I like using either groovy script runner , Jira Scripting Suite or Behaviours Plugin . All of them really makes script writing easier and much more intuitive.

like image 109
Kuf Avatar answered Dec 04 '25 02:12

Kuf