Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to bulk create projects ?

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

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

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

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,

 

@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?

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

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

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!

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

@scriptrunner 

vanessa I'm New Here Sep 11, 2020

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

Like HaRsHaS_ V likes this

@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.

Suggest an answer

Log in or Sign up to answer
TAGS

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