Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Need groovy script to copy versions one project to other project without 3rd party plugin

satyanarayana_singamsetti
Contributor
December 18, 2024

Hi,

 

Need groovy script to copy releases of one project into other project without using 3rd party plugins.

 

Thanks in advance

 

Regards,

Satya

1 answer

1 accepted

0 votes
Answer accepted
Kishan Sharma
Community Champion
December 18, 2024

Hi @satyanarayana_singamsetti 

How are you planning to execute the groovy script on your Jira data center?

satyanarayana_singamsetti
Contributor
December 18, 2024

Hi,

we have script runner plugin. So i will use it for it.

Kishan Sharma
Community Champion
December 19, 2024

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12.15
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events