Hi, I was asked to create a listener which will creates a couple of stories after creation of an epic. Then user asked me to add automatic fill of component field in the epic during the same script. Both task succeed but when I'm updating an epic with components labels 'Atlassian' and 'Oracle' then all stories are being also 'equipped' with these labels. How to prevent that?
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def issueManager = ComponentAccessor.getIssueManager()
def issue = event.issue as MutableIssue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectKey = issue.getProjectObject().key
def headings = ["Prepare Infrastructure1", "Establish Repository1"]
if (issue.issueType.name == 'Epic' && issue) {
headings.each { value ->
log.warn("Headings ${value}")
Issues.create(projectKey, "Story" ) {
setSummary("${value}")
setEpic(issue)
}
}
}
def component1 = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectId(),"Atlassian")
def component2 = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectId(),"Oracle")
issue.setComponent([component1, component2])
issueManager.updateIssue(loggedInUser,issue, EventDispatchOption.DO_NOT_DISPATCH, false)
Hi @Karol Urbaniak ,
To break down your code:
After a new Epic is created in Jira, the code automatically creates two Stories with different headings: "Prepare Infrastructure1" and "Establish Repository1".
The `setEpic(issue)` method is used to associate the newly created Stories with the Epic. This means that the Stories will be linked to the Epic in Jira.
Additionally, the code sets the Component field of the Epic using the `setComponent` method. The Component field is set with two components named "Atlassian" and "Oracle". This means that the Epic will have these components associated with it.
After the Epic is created and the Component field is set, the code updates the Epic issue using the `issueManager.updateIssue` method to save the changes.
As for why the Component field is inherited by the automatically created Stories: The Component field is set on the Epic, and then the Stories are created and associated with the Epic. Since the Stories are linked to the Epic, they inherit certain properties of the Epic, including the Component field.
To make it so that it doesn't include the components you need to remove following lines from your code:
def component1 = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectId(),"Atlassian")
def component2 = ComponentAccessor.getProjectComponentManager().findByComponentName(issue.getProjectId(),"Oracle")
issue.setComponent([component1, component2])
/Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.