The Starware

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:

  1. 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.
  2. | awk 'NR>1 {print $2}': The output from the first command is piped (|) into awk, a tool for manipulating text. The awk command used here is 'NR>2 {print $2}'. NR is an awk internal variable that keeps track of the number of records processed. NR>2 ensures that the first row (typically the header) and underscores below the header are skipped. {print $2} directs awk to print the second column, which is assumed to be the Name of the Jira project component based on your earlier message.
  3. | xargs -I {} jira project-component create --name="{}" --pKey=NEW_PROJECT_KEY: The list of names outputted by awk is then piped into xargs, a command that builds and executes command lines from standard input. The -I {} option tells xargs to replace {} in the subsequent command with each item from the input. The command that xargs executes for each input (each component name) is jira 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.