Cloning Subcomponent Hierarchy Between Projects

Following script copies all subcomponent hierarchy of source project (ERP) to target project (DUM). You can reuse the script by changing project keys. When copying hierarchy it will create all required components and virtual components in the target project.

import com.deniz.jira.versioning.subcomponents.*; import com.onresolve.scriptrunner.runner.customisers.*; import com.atlassian.jira.project.*; import com.atlassian.jira.component.*; @WithPlugin("com.deniz.jira.versioning") @PluginModule ComponentHierarchyImportExportService componentHierarchyImportExportService def projectManager = ComponentAccessor.getProjectManager() def projectComponentManager = ComponentAccessor.getProjectComponentManager() def versionManager = ComponentAccessor.getVersionManager() def sourceProjectKey = "ERP"; def targetProjectKey = "DUM"; Project srcProject = projectManager.getProjectObjByKey(sourceProjectKey) Project targetProject = projectManager.getProjectObjByKey(targetProjectKey) def node = componentHierarchyImportExportService.exportHierarchy(srcProject) componentHierarchyImportExportService.importHierarchy(targetProject, node)