How to validate issue transition by *unreleased* fixVersion via either Power Script or ScriptRunner

Šimon Demočko March 2, 2021

Hi! 

I wanted to do a workflow validation where if a ticket does not have the latest unreleased version on it.

I expected that this should be possible at least with PowerScripts or ScriptRunner if not native Jira.

I've had little success:

I tried this:

if(size(key in silJQLExpression('', 'issueKey = ' + key + ' AND fixVersion in unreleasedVersions() AND not fixVersions in releasedVersions()'))) == 0){

return false, "fixVersion", "Fix Versions blablalbla.";

}
return true;

but it always says there's some error without any further info. 

 

Any hints on how to proceed?

1 answer

1 accepted

1 vote
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 3, 2021

Hi @Šimon Demočko 

Below snippet will help you to check whether ticket is associated with released version or unreleased one

you can place this in validator or condition(scriptrunner functions)

def versions = issue.getFixVersions()
for (v in versions){
if(!v.isReleased()){
return true // there is at least one unreleased version hence returning true
}
}
return false

 

Hope this helps

 

BR,

Leo 

Šimon Demočko March 5, 2021

Thanks, looks great, I modified it a bit further into something like this: 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.search.SearchService

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService.class)

def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def query = jqlQueryParser.parseQuery("issuekey = " + issue.key + " AND development[pullrequests].merged > 0")
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())


if (results.total == 1 && issue.getResolution() in ["Fixed", "Done", "Resolved"]){
def versions = issue.getFixVersions()
if (versions.size() == 0) return false
for (v in versions){
if(!v.isReleased()){
return true
}
}
return false
}

Suggest an answer

Log in or Sign up to answer