Hi,
Need groovy script to copy releases of one project into other project without using 3rd party plugins.
Thanks in advance
Regards,
Satya
Hi @satyanarayana_singamsetti
How are you planning to execute the groovy script on your Jira data center?
we have script runner plugin. So i will use it for it.
Ok, you can run below script in the scriptrunner console, make sure to change source project key (SOURCEPROJECT) and destination project key (DESTINATIONPROJECT) in the code below.
import java.lang.Stringimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.project.Projectimport com.atlassian.jira.project.version.Versionimport com.onresolve.scriptrunner.parameters.annotation.*import java.util.ArrayList//Declare variablesdef projectManager = ComponentAccessor.getProjectManager()def projectSource = projectManager.getProjectObjByKey("SOURCEPROJECT") // Source projectdef projectDestination1 = projectManager.getProjectObjByKey("DESTINATIONPROJECT") // Destination projectdef versionManager = ComponentAccessor.getVersionManager()//Get source project objectList<Project> projectList = new ArrayList<>();projectList.add(projectSource)Collection<Version> versionList = versionManager.getAllVersionsForProjects(projectList, false)//Get target project objectList<Project> projectList2 = new ArrayList<>();projectList2.add(projectDestination1)Collection<Version> versionList2 = versionManager.getAllVersionsForProjects(projectList2, false)//Set output variableString printtext = ""//**********************************************************////Recreate all versions in the new projectprinttext+="<b>${versionList.size()}</b> Versions will now be copied from <b>${projectSource.getName()}"printtext+=" (Key: ${projectSource.getKey()})(ID: ${projectSource.id})</b> to <b>${projectDestination1.getName()}"printtext+=" (Key: ${projectDestination1.getKey()})(ID: ${projectDestination1.id})</b>"//Loop through all values that should be copiedfor(int v=0;v<versionList.size();v++){def version = versionList[v] //Source project versiondef versionname = version.getName() //Source project version nameboolean alreadyExists = false//Verify if a Fix version with the below details already existsfor(int fv=0;fv<versionList2.size();fv++){if(version.name == versionList2[fv].name){def existingPosition = fvprinttext+="<br><br>${v+1}. Fix Version/Release with the below details <b>already exist</b> in the destination project<br>"printtext+="<b>Name</b>: ${versionList2[fv].name}<br>"printtext+="<b>Start Date</b>: ${versionList2[fv].startDate}<br>"printtext+="<b>Release Date</b>: ${versionList2[fv].releaseDate}<br>"printtext+="<b>Description</b>: ${versionList2[fv].description}<br>"printtext+="<b>Destination Project ID</b>: ${projectDestination1.id}<br>"printtext+="<b>Is Released?</b>: ${versionList2[fv].released}"alreadyExists=truebreak;//}}}if(alreadyExists)continue;//Create the copy versionsif (versionname.length() >= 3){log.debug("Now adding version " + version + " to " + projectDestination1.name)versionManager.createVersion(version.name, version.startDate, version.releaseDate, version.description, projectDestination1.id,null, version.released)printtext+="<br><br>${v+1}. Version created with details:<br>"printtext+="<b>Name</b>: ${version.name}<br>"printtext+="<b>Start Date</b>: ${version.startDate}<br>"printtext+="<b>Release Date</b>: ${version.releaseDate}<br>"printtext+="<b>Description</b>: ${version.description}<br>"printtext+="<b>Destination Project ID</b>: ${projectDestination1.id}<br>"printtext+="<b>Is Released?</b>: ${version.released}"}else{printtext+="<br>${v+1}. Version not found/added"}}return printtext
It looks like you're new here. Sign in or register to get started.