Hi,
Need groovy script to copy releases of one project into other project without using 3rd party plugins.
Thanks in advance
Regards,
Satya
How are you planning to execute the groovy script on your Jira data center?
Hi,
we have script runner plugin. So i will use it for it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.String
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version
import com.onresolve.scriptrunner.parameters.annotation.*
import java.util.ArrayList
//Declare variables
def projectManager = ComponentAccessor.getProjectManager()
def projectSource = projectManager.getProjectObjByKey("SOURCEPROJECT") // Source project
def projectDestination1 = projectManager.getProjectObjByKey("DESTINATIONPROJECT") // Destination project
def versionManager = ComponentAccessor.getVersionManager()
//Get source project object
List<Project> projectList = new ArrayList<>();
projectList.add(projectSource)
Collection<Version> versionList = versionManager.getAllVersionsForProjects(projectList, false)
//Get target project object
List<Project> projectList2 = new ArrayList<>();
projectList2.add(projectDestination1)
Collection<Version> versionList2 = versionManager.getAllVersionsForProjects(projectList2, false)
//Set output variable
String printtext = ""
//**********************************************************//
//Recreate all versions in the new project
printtext+="<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 copied
for(int v=0;v<versionList.size();v++)
{
def version = versionList[v] //Source project version
def versionname = version.getName() //Source project version name
boolean alreadyExists = false
//Verify if a Fix version with the below details already exists
for(int fv=0;fv<versionList2.size();fv++)
{
if(version.name == versionList2[fv].name)
{
def existingPosition = fv
printtext+="<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=true
break;
//}
}
}
if(alreadyExists)
continue;
//Create the copy versions
if (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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.