Hello, I'd like to add a post function during the bug's resolve step to also resolve the tasks which were previously blocked by this bug (if there are no more blockers). I tried a few things but I'm new to Scriptrunner and Groovy therefore I'm asking the community.
Thanks a lot for your help, I really appreciate it :)
Thanks Josh.
I went a different way and managed to automate the transitioning of unblocked tasks using the following script:
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.ComponentManager
import com.opensymphony.workflow.WorkflowContext
import com.atlassian.jira.workflow.WorkflowTransitionUtil
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl
import com.atlassian.jira.util.JiraUtils
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
def linkMgr = ComponentAccessor.getIssueLinkManager()
def projectMgr = ComponentAccessor.getProjectManager()
for (IssueLink link in linkMgr.getOutwardLinks(issue.id)) {
def issueLinkTypeName = link.issueLinkType.name
def linkedIssue = link.getDestinationObject()
def linkProjectName = linkedIssue.getProjectObject().getName()
def linkedIssueKey = linkedIssue.getKey()
def linkedIssueID = linkedIssue.getId()
def linkedIssueStatus = linkedIssue.getStatus().getName()
def linkedIssueType = linkedIssue.issueTypeObject.name
def allResolved = true
//look for a link that blocks a projectX issue which is in 'QA Failed' status
if (issueLinkTypeName == "Blocks" && linkProjectName == "ProjectX" && linkedIssueStatus == "QA Failed"){
//go to ProjectX issue and see if it has other open blockers
for (IssueLink parentIssueLink in linkMgr.getInwardLinks(linkedIssueID)) {
def parentIssue = parentIssueLink.getSourceObject()
def parentIssueKey = parentIssue.getKey()
def parentIssueID = parentIssue.getId()
def parentIssueLinkType = parentIssueLink.issueLinkType.name
def parentIssueStatusName = parentIssue.getStatus().name
if (issue.getKey() != parentIssueKey && parentIssueLinkType == "Blocks") {
if (parentIssueStatusName != "Closed" && parentIssueStatusName != "Verified" && parentIssueStatusName != "Resolved") {
UserMessageUtil.warning("Sub-Task " + linkedIssueKey + " is still blocked by " + parentIssueKey + " (" + parentIssueStatusName + ")")
allResolved = false
} else {
UserMessageUtil.info("Sub-Task " + linkedIssueKey + " not blocked by " + parentIssueKey + " (" + parentIssueStatusName + ")")
}
}
}
//if no other blockers remain open, transition the issue
if (allResolved) {
MutableIssue linkedSubTask = linkedIssue as MutableIssue
String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller()
WorkflowTransitionUtil workflowTransitionUtil = (WorkflowTransitionUtil) JiraUtils.loadComponent(WorkflowTransitionUtilImpl.class)
workflowTransitionUtil.setIssue(linkedSubTask)
workflowTransitionUtil.setUserkey(currentUser)
workflowTransitionUtil.setAction(161) // transition for 'Done' status
if (workflowTransitionUtil.validate()) {
workflowTransitionUtil.progress()
UserMessageUtil.success("Moved task " + linkedSubTask.getKey() + " to " + linkedSubTask.getStatus().getName())
}
}
}else{
// UserMessageUtil.info("Conditions not met : "+ issue.getKey() + " type " + linkedIssueType + " - " + issueLinkTypeName + "// link : " + linkProjectName + " - " + linkedIssueKey + " - status " + linkedIssueStatus)
}
}
Hi Christophe,
I think we have a script that does this within a post-function. See here: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/auto-close-all-subtasks.html
You might have to change the resolution ID here for something else other than Fixed:
setResolutionId("1") // resolution of "Fixed"
Also you'll probably have to change the action ID '5' in this line to the ID of the action for your specific workflow that you want to apply:
def validationResult = issueService.validateTransition(user, it.id, 5, issueInputParameters)
Regards,
Josh
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.