Hello!
I’m trying to add a workflow validator to one of my transitions where the transition is blocked if a JQL query returns 0 results. Essentially, the requirement is to check that a Test Case linked to the issue, during that particular transition. We’re in the process of migrating off Zephyr Squad onto Zephyr Scale, so I can’t use the issue links functions. I also need to make the check for both Squad & Scale tests, since this workflow is common between all projects in our instance (some using Squad, some using Scale).
I’m new to groovy but my script isn’t returning any errors. However, the transition is going through, even if I don’t have tests linked. Initiaally I had this working in a Condition, but the users were getting confused why the transition is missing. Stakeholders would prefer a validator so we can show the error on transition. Here is the script I have so far, any advice is greatly appreciated!
def ScaleTests = Issues.count(‘key={issue.key} and issue in hasTestCoverage()’)
def SquadTests = Issue.count(‘key = {issue.key} and issueFunction in linkedIssuesOf(“issue type = \”Test\””)’)
if (ScaleTests <0 || SquadTests < 0)
{return false;
InvalidInputException error = new InvalidInputException();
error.addError(“Test case must be linked to issue”);
throw error;
}
return true
Hi @Dani Lynch
Are you sure you are not getting any errors? I don't know Zephyr but I can try to help you with the script.
I don't think either Issue.count or Issues.count will wok as they are not Groovy valid syntax. You can use SearchService to search by JQL. I assume hasTestCoverage is valid in Zephyr, and below is the script which may help you start with. I hope it helps
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchService
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.workflow.WorkflowFunctionUtils
import com.opensymphony.workflow.InvalidInputException
def issue = transientVars["issue"] // Get the current issue
def jqlQueryParser = ComponentAccessor.getComponent(SearchService.JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def scaleTestQuery = "key = ${issue.key} AND issue in hasTestCoverage()"
def squadTestQuery = "key = ${issue.key} AND issueFunction in linkedIssuesOf('issueType = \"Test\"')"
def scaleTestResults = searchService.search(user, jqlQueryParser.parseQuery(scaleTestQuery), PagerFilter.getUnlimitedFilter())
def scaleTestsCount = scaleTestResults.total
def squadTestResults = searchService.search(user, jqlQueryParser.parseQuery(squadTestQuery), PagerFilter.getUnlimitedFilter())
def squadTestsCount = squadTestResults.total
if (scaleTestsCount == 0 && squadTestsCount == 0) {
InvalidInputException error = new InvalidInputException()
error.addError("Test case must be linked to the issue before transitioning.")
throw error
}
return true
Hi @Tuncay Senturk _Snapbytes_ ,
Thank you for your insight! I’m unfortunately now getting an error on the import statement. Startup failed; unable to resolve class com.Atlassian.Jira.issue.search.SearchService
Would you know how to resolve?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which Jira version are you using? and can you confirm that this is Jira Datacenter?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.