Is there a way to copy components from one Jira project to another and/or import from a text list that does not involve a paid plugin?

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2016

I'm copying components from one project to another - manually - and this is painful.  I would love to find a way to just bulk copy the components over, or at least import from a list.  Paid components are not an option.

4 answers

1 accepted

2 votes
Answer accepted
Nicolas Bourdages
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2016

You could use the CSV import tool to create a bunch of bogus issues with the components you want. It's messy as it leaves behind unwanted issues, but I think it would work.

Any reason why you can't use the the REST api?

https://docs.atlassian.com/jira/REST/latest/#api/2/component-createComponent

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2016

Any reason why you can't use the the REST api?

Ummm... because I don't know how smile

Like # people like this
Nicolas Bourdages
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2016

That's a good reason. It might be worth the time investment if you're going to do that sort of task again. Personally, I use the CLI plugin whenever I can, but it's paid, so sad

For the REST api, you'd need some basic coding skills. Here's something to get you started:

https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis

Good luck!

Like Naomi likes this
1 vote
Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 29, 2016
Martin Gregory November 19, 2017

But that only works for Server :(

gianfranco franceschi January 29, 2018

Martin, what do you mean? 

That if I have got Jira Cloud there is no point in downloading the plugin? 

Just by typing the question I realize that it may very well be the meaning :-)

Anyway, is there really no other options to accomplish this? 

Best,

Gianfranco

0 votes
Michelle Rau good
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2019

I found a way to create a simple list of components (or labels) which I posted here: https://community.atlassian.com/t5/Jira-questions/How-do-I-get-a-list-of-active-components-in-JIRA-and-export-them/qaq-p/419207

I don't know about importing components from a list though.

0 votes
Bryan Karsh November 7, 2018

I realize this solution uses a paid plugin. But I am adding it because I ran into the same need, and whipped something up. Hopefully it will be of help to folks.

This can be run via script runner in the script runner console. It's pretty crude -- it simply adds the strings in the list to the target project as components (if I have time, I will refactor it to be a little more flexible -- it's not that hard (for example) to copy the stuff from the source project to a target project).

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("Component Backfill Script")
log.setLevel(Level.DEBUG)


def projectComponentManager = ComponentAccessor.getProjectComponentManager()

// The projectkey and id of where you want the components to be added

def projectKey = "FOOBAR"
Long projectId = 12345

def newComponent = ""

def componentList = ["apple", "banana", "orange"]

componentList.each {

newComponent = it

/* see the blank quotes below? You can specify description and user for each
component. But if you do that, you'll need to add logic that parses that
additional information, or programmatically pull it from components from
the source project

*/
try {
projectComponentManager.create(newComponent, "", "", 1, projectId)
log.debug "Created component ${newComponent} for project ${projectKey}"
}

catch(e) {
log.debug "Ran into a problem creating a component for ${projectKey} n\" + e.message"
}



}



 

Rob Horan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2018

Thanks - we didn't have scriptrunner, though. 

Bryan Karsh November 8, 2018

No worries. If I have time, I will show a pure rest-api approach. :)

Daniel August 19, 2019

Thanks Bryan,

 

i addapted your scrip to pull all components from one project and insert them into another:

 

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("Component Backfill Script")
log.setLevel(Level.DEBUG)


def projectComponentManager = ComponentAccessor.getProjectComponentManager()
//def projectManager = ComponentAccessor.getProjectManager()

// The projectkey and id of where you want the components to be added

Long projectId = 12345 // Project ID to copy components from
def projectKeyTo = "HSR" // Project Key to copy to
Long projectIdTo = 11111 // Project ID to copy to

def newComponent = ""
def componentList = projectComponentManager.findAllForProject(projectId)
componentList.each {

newComponent = it
/* see the blank quotes below? You can specify description and user for each
component. But if you do that, you'll need to add logic that parses that
additional information, or programmatically pull it from components from
the source project

*/
try {
projectComponentManager.create(newComponent.name, newComponent.description, newComponent.lead, newComponent.assigneeType, projectIdTo)
log.debug "Created component ${newComponent} for project ${projectKeyTo}"
}

catch(e) {
log.debug "Ran into a problem creating a component for ${projectKey} n\" + e.message"
}
}
Like ITMSD likes this
Daniel August 19, 2019
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Logger
import org.apache.log4j.Level

def log = Logger.getLogger("Component Backfill Script")
log.setLevel(Level.DEBUG)


def projectComponentManager = ComponentAccessor.getProjectComponentManager()
//def projectManager = ComponentAccessor.getProjectManager()

// The projectkey and id of where you want the components to be added

Long projectId = 12345
def projectKeyTo = "ABC"
Long projectIdTo = 11111


def newComponent = ""
def componentList = projectComponentManager.findAllForProject(projectId)

componentList.each {

newComponent = it

/* see the blank quotes below? You can specify description and user for each
component. But if you do that, you'll need to add logic that parses that
additional information, or programmatically pull it from components from
the source project

*/
try {
projectComponentManager.create(newComponent.name, newComponent.description, newComponent.lead, newComponent.assigneeType, projectIdTo)
log.debug "Created component ${newComponent} for project ${projectKeyTo}"
}

catch(e) {
log.debug "Ran into a problem creating a component for ${projectKey} n\" + e.message"
}




}
Like # people like this
Maxim Rodionov September 24, 2019

It works for me! Thanks!

Suggest an answer

Log in or Sign up to answer