Hi,
After searching around this site and Google and refering to the Script Runner confluence page I just can't get my validator script to work and need some help.
I am trying to implement a simple validator script that will check the following for the issue being transitioned:
1) there must be at least 1 linked issue with a name of Test
2) assuming statement 1 above is true then all linked issues with a name of Test must be in a specific status
The code I have so far is:
import com.atlassian.jira.ComponentManager import org.apache.log4j.Category import com.atlassian.jira.issue.link.IssueLink; import com.opensymphony.workflow.InvalidInputException log = Category.getInstance("com.onresolve.jira.groovy.LinkedIssues") testlinkType = ["Test"] linkMgr = ComponentManager.getInstance().getIssueLinkManager() // We are looking for the Inward Link of "Is Tested By" for (IssueLink link in linkMgr.getInwardLinks(issue.id)) { if ((testlinkType.contains(link.issueLinkType.name))) { if (!link.getSourceObject().getStatusObject() == "Template") { invalidInputException = new InvalidInputException("Linked issue " + link.getId() + " is not in a status of Template") } } }
Any help would be greatly appreciated.
Thanks.
I figured it out - I was not using the getName() method i.e. link.getSourceObject().getStatusObject().getName())
Would you mind posting the complete script? I'm looking to check status of linked issues as well.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I would like the complete script too since I'm trying to do the exact same thing. Could you post it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
Sorry for such a late response!
Here is the script I created in the end.
Steve
import com.atlassian.jira.ComponentManager import org.apache.log4j.Category import com.atlassian.jira.issue.link.IssueLink; import com.opensymphony.workflow.InvalidInputException log = Category.getInstance("com.onresolve.jira.groovy.LinkedIssues") log.debug("issue key: " + issue.key) passesCondition = true testlinkType = ["Test"] testlinkStatus = ["Template"] linkMgr = ComponentManager.getInstance().getIssueLinkManager() // Check for at least 1 inward Test issue if (!linkMgr.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Test')) { log.debug("no Test issue links exist") invalidInputException = new InvalidInputException("There must be at least 1 'is tested by' link") throw invalidInputException // return false } // We are looking for the Inward Link of "Is Tested By" for (IssueLink link in linkMgr.getInwardLinks(issue.id)) { log.debug("linked issue type: " + link.issueLinkType.name) log.debug("linked issue key: " + link.getSourceObject().getKey()) log.debug("linked issue status (name): " + link.getSourceObject().getStatusObject().getName()) log.debug("linked issue status (id): " + link.getSourceObject().getStatusObject().getId()) if ((testlinkType.contains(link.issueLinkType.name))) { log.debug("we have a Test issue")
// The issue needs to be in a Template status if (!link.getSourceObject().getStatusObject().getName().contains("Template")) { log.debug("issue " + link.getSourceObject().getKey() + " is not in Template state") invalidInputException = new InvalidInputException("Linked issue " + link.getSourceObject().getKey() + " is not in a status of Template") throw invalidInputException } } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, wonder if you can help? I need a script which validates the issue type before transition to next status.
So for example on transtion to "Review & Planning" the issue type must be set to "Bug", Change Control", "GAP", "Enhancement" or "Configuration".
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Updated for JIRA 7-
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.link.IssueLinkManager import org.apache.log4j.Category import com.atlassian.jira.issue.link.IssueLink; import com.opensymphony.workflow.InvalidInputException def Category log = Category.getInstance("com.onresolve.jira.groovy.LinkedIssues") log.debug("issue key: " + issue.key) Boolean passesCondition = true String testlinkType = ["Test Case"] String testlinkStatus = ["Active"] IssueLinkManager linkMgr = ComponentAccessor.getIssueLinkManager() // Check for at least 1 inward Test issue if (!linkMgr.getInwardLinks(issue.getId())*.issueLinkType.name.contains('Test Case')) { log.debug("no Test Case issue links exist") invalidInputException = new InvalidInputException("There must be at least 1 'executes' link") throw invalidInputException // return false } // We are looking for the Inward Link of "Is Tested By" for (IssueLink link in linkMgr.getInwardLinks(issue.id)) { log.debug("linked issue type: " + link.issueLinkType.name) log.debug("linked issue key: " + link.getSourceObject().getKey()) log.debug("linked issue status (name): " + link.getSourceObject().getStatus().getName()) log.debug("linked issue status (id): " + link.getSourceObject().getStatus().getId()) if ((testlinkType.contains(link.issueLinkType.name))) { log.debug("we have a Test Case issue") // The issue needs to be in an Active status if (!link.getSourceObject().getStatus().getName().contains("Active")) { log.debug("issue " + link.getSourceObject().getKey() + " is not in Active state") invalidInputException = new InvalidInputException("Linked issue " + link.getSourceObject().getKey() + " is not in a status of Active") throw invalidInputException } } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.