问题
I am new to JIRA and Kanban. I was expecting that when I create an epic and link some stories and tasks to it. The status of the epic will automatically change (e.g. to done) when all the stories and tasks linked to it are done. But it seems this is not the case. I can move the epic from the Backlog to the Done column even when its linked tasks and stories are still in the backlog. Is there a way to make JIRA prevent that from happening?
回答1:
I have been working on something similar. My intention was to set assigne of all linked issues of another one to a specific user when the status changes to a specific state.
I did this with a postfunction of the workflow of type: "Set Field Value to constant or Groovy expression"
In your situation I would do the following:
- go to "Close" transition, and click configure.
- select postfunctions, and add the type i told you.
- mark the chekbox that says execute only if condition is true
- set your condition. Probably something like issue.epic=your epic.
- Then you add your script, where you recover alll the issues linked to the epic, and check their status.
- Create your logic so that if everithing is as it should be, you just change the status, using MutableIssue object.
- remember that a field is going to be modified by this script, and i guess you cant choose status as field to be set. If this happens, choose summary, and store the current value, and use it to end your script, and set the summary value, whtih the same you had.
- Publish your workflow.
Excuse me if it is not clear, but is difficult to explain. Let me know if you need somenthing else.
PD: If you just want to do this at some specific moment and not for every epics automatically, just add Script Runner plugin, and run your script in the console. Much easier.
Regards
回答2:
Maybe it helps you: I used jira with system language set to "Russian" (and i'm not good in groovy), that's why script below contains language dependencies (you should edit code if you use differ from my jira system language! At least change )
- Use Scrip Runner plugin
Create "Custom listener" and paste code (code is not so good as can be but it's working):
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.Issue; import com.atlassian.jira.issue.link.IssueLinkManager; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.ModifiedValue; import com.atlassian.jira.issue.util.DefaultIssueChangeHolder; import com.atlassian.jira.issue.customfields.option.Options; import com.atlassian.jira.issue.customfields.option.Option; import com.atlassian.jira.issue.fields.config.FieldConfig; import com.atlassian.jira.issue.customfields.manager.OptionsManager; import com.atlassian.jira.ComponentManager; ComponentManager componentManager = ComponentManager.getInstance(); def groupMan = ComponentAccessor.getGroupManager() def authCon = ComponentAccessor.getJiraAuthenticationContext() def customFieldManager = ComponentAccessor.getCustomFieldManager() def changeHolder = new DefaultIssueChangeHolder(); IssueManager issueManager = ComponentAccessor.getIssueManager(); OptionsManager optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class); IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager() def curUser = authCon.getUser() def issue = event.issue def epicLinkCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'} if(!epicLinkCf) {log.warn "No Epic Link field"; return} log.warn "Existing Epic Link: ${epicLinkCf.getValue(issue)}" String epicIssue = epicLinkCf.getValue(issue) Issue epic = issueManager.getIssueObject(epicIssue) // epicKey is passed into your script // Check if Epic link is exist if(!epic) return true def newEpicState = "Сделано" log.warn "Epic: " + epic List<IssueLink> allOutIssueLink = issueLinkManager.getOutwardLinks(epic.getId()); for (Iterator<IssueLink> outIterator = allOutIssueLink.iterator(); outIterator.hasNext();) { IssueLink issueLink = (IssueLink) outIterator.next(); log.warn "child link type: " + issueLink.getIssueLinkType().getName() // Check status of all issues from epic if (issueLink.getIssueLinkType().getName() == "Epic-Story Link") { Issue chIssue = issueLink.getDestinationObject(); log.warn "child state: " + chIssue.getStatusObject().getName() if(chIssue.getStatusObject().getName() == "В процессе") { newEpicState = "В процессе" } else if (chIssue.getStatusObject().getName() != "Закрыто" && newEpicState != "В процессе") { newEpicState = "Сделать" } } } def epicStatusCf = customFieldManager.getCustomFieldObjects(epic).find {it.name == 'Epic Status'} log.warn "Current epic status: " + epicStatusCf.getValue(epic) FieldConfig epicStatusFieldConfig = epicStatusCf.getRelevantConfig(epic); String oldStatus = epicStatusCf.getValue(epic) log.warn "New epic status: " + newEpicState // Set new status if it necessary if (oldStatus != newEpicState) { Options epicStatusOptions = optionsManager.getOptions(epicStatusFieldConfig); Option epicStatusDoneOption = epicStatusOptions.getOptionForValue(newEpicState, null); epicStatusCf.updateValue(null, epic, new ModifiedValue(epic.getCustomFieldValue(epicStatusCf),epicStatusDoneOption),changeHolder) log.warn "Epic status is updated!" }
来源:https://stackoverflow.com/questions/35468017/is-there-a-way-to-automatically-change-epic-state-to-done-when-all-the-linked-st