Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Jira copy project components/Fix versions to another project component/Fix versions in Data center


I am tryin to 

copy project components/Fix versions to another project component/Fix versions in Data center.

I used approach CSV import but it is missing few data still,

can anyone tell any other approach by using Rest API or Script runner through.


Thank you 

2 answers

1 accepted

0 votes
Answer accepted

Hi @vasanth

For your requirement, you will need to use the REST Endpoint to get the versions from the previous project and the ScriptRunner console to copy the versions into the second project.

For the REST Endpoint, you can try something like this:-

import groovy.json.JsonBuilder
import groovy.transform.BaseScript


@BaseScript CustomEndpointDelegate delegate
convertToJson { MultivaluedMap queryParams ->

def hostUrl = "http://localhost:9091"
def userName = "admin"
def password = "q"
def projectKey = "SFFM"

def httpBuilder = new HTTPBuilder(hostUrl)

def versions = [] as List

def issueJson = httpBuilder.request(Method.GET, ContentType.JSON) { req ->

uri.path = "/rest/api/2/project/${projectKey}/versions"

headers.'Authorization' = "Basic ${"${userName}:${password}".bytes.encodeBase64()}"

response.failure = { resp, reader ->
log.warn "Failed to query JIRA API: ${reader.errorMessages}"
issueJson.collect { Map row ->

return Response.ok(new JsonBuilder(versions).toPrettyString()).build()

Please note, the sample codes provided are not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the REST Endpoint configuration:-


If you notice in the code, the versions are taken from the  Scripted Field For Mail (SFFM) project. 

Once your REST Endpoint is configured, you will need to invoke it using the ScriptRunner console. 

Below is a sample code for your reference:-

import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonSlurper

def projectManager = ComponentAccessor.projectManager
def versionManager = ComponentAccessor.versionManager

def baseUrl = "http://localhost:9091"

final String projectKey = "COM"

final Date startDate = null

final Date releaseDate = null

final String description = null

final Long scheduleAfterVersion = null

final boolean released = false

def project = projectManager.getProjectObjByKey(projectKey)

def hostUrl = "${baseUrl}/rest/scriptrunner/latest/custom/convertToJson"

def response = hostUrl.toURL().text

def json = new JsonSlurper().parseText(response)

def artifacts = json.collect().sort()

artifacts.each {
versionManager.createVersion(it.toString(), startDate, releaseDate, description,, scheduleAfterVersion, released)

In the code above, the code is to be stored in the Communications (COM) project.

Below is a print screen of the Script Console:-


Below are some test screens:-

1) Below is the version screen for the Communication project before the script is executed.


2) Once the script is executed on the Script Console, the list of versions will be displayed in a list as shown in the image below:-


3) Now, if you go to the version page once again, you will see that the versions have been added, as shown below:-


I hope this helps to solve your question. :)

Thank you and Kind Regards,


Hi @vasanth

I'm glad to hear the solution helped. :)

Please accept the answer.

Thank you and Kind regards,


Like vasanth likes this

Using the Console of ScriptRunner you can use the below code to clone the versions of the Master project to sub-projects.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.version.Version

def projectManager = ComponentAccessor.getProjectManager()
def projectSource = projectManager.getProjectObjByKey("SourceProjectKey") // Source project name here
def projectDestination1 = projectManager.getProjectObjByKey("DestinationProjectKey") // Destination project name here

def versionManager = ComponentAccessor.getVersionManager()
List<Project> projectList = new ArrayList<>();

Collection<Version> versionList = versionManager.getAllVersionsForProjects(projectList, false)

for (version in versionList) {
def versionname = version.getName()

if (versionname.length() >= 3) {
log.debug("Now adding version " + version + " to " +
versionManager.createVersion(, version.startDate, version.releaseDate, version.description,,null, version.released)
else {
//do nothing

Suggest an answer

Log in or Sign up to answer

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you