I am firing an event based on a transition called "Generate Features" executed as you can see below:
Also, based on an automation rule, I am executing some code. Here is the automation rule that I have:
The problem is that I am getting a message saying that the issue does not have an component which is wrong since the issue that I am testing my code on has 2 components as you can see below: Here is the code to be executed as part of the automation rule:
package SuperFeature import com.atlassian.jira.issue.Issue import org.apache.log4j.Logger import com.atlassian.jira.project.version.Version import com.atlassian.jira.bc.project.component.ProjectComponent import com.atlassian.jira.bc.project.component.ProjectComponentManager import com.atlassian.jira.security.JiraAuthenticationContext import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.label.LabelManager def log = Logger.getLogger('atlassian-jira.log') List < String > componentList = new ArrayList < String > () List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > () def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF'] log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents()) if (issue.getComponents().size() == 0) { issue.update { String text = "Issue does not have any components\n" setCustomFieldValue('Execution Summary', text ) } } else if (issue.getFixVersions().size() == 0) { issue.update { String text = "Issue does not have any fix versions\n" setCustomFieldValue('Execution Summary', text) } } else { int componentSize = issue.getComponents().size() int generatedIssuesCounter= 0 for (ProjectComponent component: issue.getComponents()) { String componentName = component.getName() def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1) def projectName = componentName.substring(0, componentName.indexOf("-")) if(projectNames.contains(projectName)){ def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName) //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList) List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents()); def found = newList.any { it.getName().equals(shortenedComponentName) } if (found) { componentList.add(componentName+" ===> WILL BE GENERATED") finalComponentList.add(component) generatedIssuesCounter++ } else{ componentList.add(componentName+" ===> CANNOT BE GENERATED") } } } issue.update { String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n" text = text + componentList.join("\n") ; // Partition a list into list of lists size 3 setCustomFieldValue('Execution Summary', text) } }
Hello @Mouna Hammoudi
can you create new automation rule with Manual trigger from issue and then try to run in from the certain issue? Skipping the event triggering part? If the script is working correctly?
Thanks,
Tomas
@Tomáš Vlach yes, the implementation I had before was based on an issue update and it was working perfectly.
In that case, in you current rule try to add component - FOR EACH: Create a branch - Branch rule / related issue - Current issue - Save and then in this component add run a script action.
Tom
@Tomáš Vlach
I was wrong, I have used issue updated as an automation trigger for my rule and it's not working, I receive the message, the issue does not have any components even though the issue does have components.
You can see it in these screenshots:
Here is the code which is supposed to be executed based on an issue update. I printed the issue and I have gotten the following: =====MOUNA CAMELIA ISSUE:::: SF-437 ISSUE COMPONENTS []
The issue components are empty which is obviosuly wrong. My issue does have components.
package SuperFeatureimport com.atlassian.jira.issue.Issueimport org.apache.log4j.Loggerimport com.atlassian.jira.project.version.Versionimport com.atlassian.jira.bc.project.component.ProjectComponentimport com.atlassian.jira.bc.project.component.ProjectComponentManagerimport com.atlassian.jira.security.JiraAuthenticationContextimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.label.LabelManager def log = Logger.getLogger('atlassian-jira.log')List < String > componentList = new ArrayList < String > ()List < ProjectComponent > finalComponentList = new ArrayList < ProjectComponent > ()def projectNames = [ 'WF', 'BF', 'EF', 'YF', 'CLTF']log.warn("=====MOUNA CAMELIA ISSUE:::: "+ issue +" ISSUE COMPONENTS "+issue.getComponents())if (issue.getComponents().size() == 0) { issue.update { String text = "Issue does not have any components\n" setCustomFieldValue('Execution Summary', text ) }} else if (issue.getFixVersions().size() == 0) { issue.update { String text = "Issue does not have any fix versions\n" setCustomFieldValue('Execution Summary', text) }} else { int componentSize = issue.getComponents().size() int generatedIssuesCounter= 0 for (ProjectComponent component: issue.getComponents()) { String componentName = component.getName() def shortenedComponentName = componentName.substring(componentName.indexOf("-") + 1) def projectName = componentName.substring(0, componentName.indexOf("-")) if(projectNames.contains(projectName)){ def newIssueproject = ComponentAccessor.projectManager.getProjectObjByKey(projectName) //log.warn("MOUNA CAMELIA found--"+found+"--NEW LIST SIZE: "+newList) List < ProjectComponent > newList = new ArrayList < > (newIssueproject.getComponents()); def found = newList.any { it.getName().equals(shortenedComponentName) } if (found) { componentList.add(componentName+" ===> WILL BE GENERATED") finalComponentList.add(component) generatedIssuesCounter++ } else{ componentList.add(componentName+" ===> CANNOT BE GENERATED") } } } issue.update { String text = "The super feature " + issue + " will be split into " + generatedIssuesCounter + " features, one for each component:\n" text = text + componentList.join("\n") ; // Partition a list into list of lists size 3 setCustomFieldValue('Execution Summary', text) }}
It looks like you're new here. Sign in or register to get started.