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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could this be modified to use an array containing projectkey, projectname, and project description?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Aidan Derossett [Adaptavist] , can you please help tweak this script to create multiple projects with different names in Jira 8.5 version.?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, this would be helpful for me as well. @scriptrunner
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.