How to create projects based on a template
Description
Many organizations need to create projects based on a standard process. This shows how to automate doing this type of activity to ensure consistency. This example is based on using the run action, but similar techniques (runFromCsv, etc...) will work similarly.
If you use Confluence in your organization
How to create a self service create project page describes a technique for delegating administrative tasks like this to project leaders.
Steps
Create an action script.
Example action script# Create a new project based on a template project --action cloneProject --project template --toProject #PROJECT# --name #NAME# # Add more plans --action clonePlan --plan #PROJECT#-UI --toPlan #PROJECT#-UI2 --name UI2 --action clonePlan --plan #PROJECT#-UI --toPlan #PROJECT#-UI3 --name UI3 # Add a script task to UI2 --action addTask --build #PROJECT#-UI2 --job "JOB1" --taskKey "com.atlassian.bamboo.plugins.scripttask:task.builder.script" --fields "argument:ui2" --field1 "scriptLocation" --value1 "INLINE" --field2 "scriptBody" --value2 "echo 'this is just an example'" # Enable all plans in the new project --action enableProject --project #PROJECT# # Queue an initial build for UI2 --action queueBuild --wait --build #PROJECT#-UI2 Â ... other actions
Run the action from a command line.
Commandbamboo -action run --file CreateProject.txt --findReplace "#PROJECT#:SAMPLESOFT,#NAME#:Samplesoft"
Results# Create a new project based on a template project Run: --action cloneProject --project template --toProject SAMPLESOFT --name Samplesoft Build plan SAMPLESOFT-IT created based on TEMPLATE-IT. Build plan SAMPLESOFT-PRIM created based on TEMPLATE-PRIM. Build plan SAMPLESOFT-UI created based on TEMPLATE-UI. 3 build plans cloned from TEMPLATE to SAMPLESOFT. # Add more plans Run: --action clonePlan --plan SAMPLESOFT-UI --toPlan SAMPLESOFT-UI2 --name UI2 Build plan SAMPLESOFT-UI2 created based on SAMPLESOFT-UI. Run: --action clonePlan --plan SAMPLESOFT-UI --toPlan SAMPLESOFT-UI3 --name UI3 Build plan SAMPLESOFT-UI3 created based on SAMPLESOFT-UI. # Add a script task to UI2 Run: --action addTask --build SAMPLESOFT-UI2 --job "JOB1" --taskKey "com.atlassian.bamboo.plugins.scripttask:task.builder.script" --fields "argument:ui2" --field1 "scriptLocation" --value1 "INLINE" --field2 "scriptBody" --value2 "echo 'this is just an example'" Script task with id 2 added to job SAMPLESOFT-UI2-JOB1. # Enable all plans in the new project Run: --action enableProject --project SAMPLESOFT Build plan SAMPLESOFT-IT enabled. Build plan SAMPLESOFT-PRIM enabled. Build plan SAMPLESOFT-UI enabled. Build plan SAMPLESOFT-UI2 enabled. Build plan SAMPLESOFT-UI3 enabled. Project SAMPLESOFT enabled. 5 build plans enabled. # Queue an initial build for UI2 Run: --action queueBuild --wait --build SAMPLESOFT-UI2 Build SAMPLESOFT-UI2 submitted with build number: 1, build result key: SAMPLESOFT-UI2-1. Waiting . Build SAMPLESOFT-UI2-1 completed successfully. Run completed successfully. 6 actions were successful from file: CreateProject.txtÂ
Tips
Use common
--common is used to avoid duplicating parameters across many of the actions. It simply provides all the parameters on each of the actions run. Only include parameters that will not duplicate provided parameters and provide the correct value on all actions being run.
Use findReplace
Use --findReplace or --findReplaceRegex to parameterize your action script to enforce rules or prevent duplication.
Confluence installed?
If you have Confluence, you can do this kind of administrative action from a page using the Run CLI Actions in Confluence - How to semi-automate repetitive tasks
Automate as part of a Jira workflow
The Run CLI Actions in Jira provides a way to do this kind of activity as part of a workflow. Your process could have a "Create a new project" task that drives the automation to create the project from a workflow based on custom fields settings.