Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner: custom script post-function to resolve previously blocked issues

Christophe Paquignon October 30, 2018

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 :)

2 answers

1 accepted

0 votes
Answer accepted
Christophe Paquignon November 1, 2018

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)
}
}





0 votes
Joshua Yamdogo @ Adaptavist
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2018

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events