How to bulk create projects ?

CST JIRA Confluence Admin May 23, 2017

Using a Template (an project with all required Schemes, Board, Workflow), is it possible to create many project in one go ?

Currently only one at a time is possible using " Copy Project " of Scriptrunner by Adaptavist.

There is a need to create about 15 projects using a Template

Any possibilities or ideas, much appreciated.

2 answers

1 accepted

2 votes
Answer accepted
Aidan Derossett _Adaptavist_
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.
May 24, 2017

Hey there!

I saw your question while doing support, so I thought that I'd just pop over here and answer it for you. Next time you make a community question, however, it is a good idea to add the "scriptrunner" tag. We on the ScriptRunner team pay pretty close attention to questions that fall within that tag and work on them as frequently as we can. 

Without any further delay, I've written a script that should work as a template to accomplish what you're looking for. You will find it below:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject

def projectManager = ComponentAccessor.getProjectManager()

def params = [:]
def copyProject = new CopyProject()
def parentProject = projectManager.getProjectByCurrentKey("GIB")

(1..15).each{
    params = [
            (CopyProject.FIELD_SOURCE_PROJECT) : parentProject.getKey(),
            (CopyProject.FIELD_TARGET_PROJECT) : "PROJKEY$it",
            (CopyProject.FIELD_TARGET_PROJECT_NAME) : "PROJNAME$it",
            (CopyProject.FIELD_COPY_VERSIONS) : true,
            (CopyProject.FIELD_COPY_COMPONENTS) : true,
            (CopyProject.FIELD_COPY_ISSUES) : true,
            (CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,
            (CopyProject.FIELD_CLONE_BOARD_NAME) : parentProject.name+"Board $it"
    ]

    copyProject.doScript(params)
}

To create this, I used the CopyProject class that is used in the built-in script. I make a new CopyProject instance and grab the project that I'd like to use as the template via its key (parentProject). I then use a closure to define the necessary map of parameters that will be used for each noew project. From there it's as simple as calling the doScript method with the CopyProject instance that was initialized previously (passing in the params map as an argument). 

The script that I've provided is pretty bare-bones and can be added upon. The strings that I set for the target project values are just meant to be generic and unique. However, you can use a list or collection of your own values to fill in those ambiguous ones that I preset.

I hope that helps!

Aidan

CST JIRA Confluence Admin May 24, 2017

Hi Aidan,

Thanking you for the script, it seems to create only one project, for example, TEST1, but not TEST2, TEST3....& so on.

Also the board doesn't as well. Gives error as below

With below board name as below

 (CopyProject.FIELD_CLONE_BOARD_NAME) : "Test$it Board"

It gives error, but no board created

com.onresolve.scriptrunner.canned.jira.utils.plugins.BoardSelectionException: Must be one and only one rapid view with this name: 'Test1 Board'
 at com.onresolve.scriptrunner.canned.jira.utils.plugins.RapidBoardUtils.cloneRapidBoard(RapidBoardUtils.groovy:52)
 at com.onresolve.scriptrunner.canned.jira.utils.plugins.RapidBoardUtils$cloneRapidBoard$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.utils.plugins.RapidBoardUtils.cloneRapidBoard(RapidBoardUtils.groovy:35)
 at com.onresolve.scriptrunner.canned.jira.utils.plugins.RapidBoardUtils$cloneRapidBoard.call(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.admin.CopyProject.cloneRapidBoard(CopyProject.groovy:744)
 at com.onresolve.scriptrunner.canned.jira.admin.CopyProject.doCopyProject(CopyProject.groovy:564)
 at com.onresolve.scriptrunner.canned.jira.admin.CopyProject$doCopyProject.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.admin.CopyProject.doScript(CopyProject.groovy:289)
 at com.onresolve.scriptrunner.canned.CannedScript$doScript.call(Unknown Source)
 at Script153$_run_closure1.doCall(Script153.groovy:22)
 at Script153.run(Script153.groovy:10)

Why this isn't looping thru' to create rest 14 projects, is that [1..15] to be declared differently ?

Thanks in advance

Aidan Derossett _Adaptavist_
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.
May 25, 2017

I believe it is only creating one project because it is getting that error that you mentioned above. That error is most likely occuring because you do not have a board set for your template project. If the project that you are copying does not have a board, then you need to set this map value to false as I did in my example:

(CopyProject.FIELD_COPY_DASH_AND_FILTERS) : false,

 

Like Chris Langenberg likes this
Eric Andersen January 26, 2018

@Aidan Derossett _Adaptavist_  This only appears to work for JIRA Server since the JIRA Cloud Scriptrunner has a very limited set of allowed imports.  Do you have a solution for JIRA Cloud?

Devan Dewey January 11, 2019

Could this be modified to use an array containing projectkey, projectname, and project description?

John Matthew Bloise September 5, 2019

Is it possible to use this to loop through a CSV or array like Devan Dewy said above? Im unable to get this code to work, im receiving the error below.2019-09-05_9-20-47.png

Abraham - New Verve Consulting January 6, 2020

Hiya!

I was having he same issues / getting similar errors and this is the code that worked for me (I modified it a bit to make it a bit more noob-friendly hehe)


import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import groovy.transform.Field

def projectManager = ComponentAccessor.getProjectManager()

def params = [:]
def copyProject = new CopyProject()
def parentProject = projectManager.getProjectByCurrentKey("KS")

for (def i=0; i<10; i++) {
   params = [
      FIELD_SOURCE_PROJECT : parentProject.getKey(),
      FIELD_TARGET_PROJECT : "PKEY" + i,
      FIELD_TARGET_PROJECT_NAME : "PNAME" + i,
      FIELD_COPY_VERSIONS : false,
      FIELD_COPY_COMPONENTS : false,
      FIELD_COPY_ISSUES : false,
      FIELD_COPY_DASH_AND_FILTERS : false
   ]

   copyProject.doScript(params)
}

 

Hope that helps!

0 votes
HaRsHaS' V September 8, 2020

@Aidan Derossett _Adaptavist_ , can you please help tweak this script to create multiple projects with different names in Jira 8.5 version.?

@scriptrunner 

Vanessa September 11, 2020

Hi, this would be helpful for me as well. @scriptrunner 

Like HaRsHaS' V likes this
HaRsHaS' V September 11, 2020

@Vanessa , I reached out to scriptrunner, unfortunately they declined to tweak this script and gave me this same link. We should only wait if any one from the community can give any insight into this, hopefully. If I create a  new post I will tag you in that too.

Katy Kelly
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.
December 27, 2020

Hi @HaRsHaS' V ,

If you would like tweak this script or write something custom, read about our Scripting Service, a flexible offering that leverages our team of expert ScriptRunner developers.

Kind regards,

Katy

Adaptavist Product Support 

Suggest an answer

Log in or Sign up to answer