Copy All Components from One Jira Project to Another
Using AtlasCLI for Jira you can copy all of the project components from one project to another one with one liner.
Using AtlasCLI for Jira you can copy all of the project components from one project to another one with one liner.
jira project-component get-all --project=OLD_PROJECT_KEY | awk 'NR>1 {print $2}' | xargs -I {} jira project-component create --name="{}" --pKey=NEW_PROJECT_KEY
Here’s the breakdown of each part:
jira project-component get-all --project=OLD_PROJECT_KEY: This part runs a JIRA CLI command to get all the components of the project identified by the key_OLD_PROJECT_KEY_. The output is actually a table of data about each component.| awk 'NR>1 {print $2}': The output from the first command is piped (|) intoawk, a tool for manipulating text. Theawkcommand used here is'NR>2 {print $2}'.NRis anawkinternal variable that keeps track of the number of records processed.NR>2ensures that the first row (typically the header) and underscores below the header are skipped.{print $2}directsawkto print the second column, which is assumed to be theNameof the Jira project component based on your earlier message.| xargs -I {} jira project-component create --name="{}" --pKey=NEW_PROJECT_KEY: The list of names outputted byawkis then piped intoxargs, a command that builds and executes command lines from standard input. The-I {}option tellsxargsto replace{}in the subsequent command with each item from the input. The command thatxargsexecutes for each input (each component name) isjira project-component create --name="{}" --pKey=NEW_PROJECT_KEY. This uses the JIRA CLI to create a new component in the project_NEW_PROJECT_KEY_with the name taken from the input.
In summary, this one-liner first fetches the component names from an existing JIRA project, then iteratively creates each of those components in a new project, all via command line interfaces, automating what could be a very repetitive task.