As I have several types of projects in my instance, I created several templates.
So, I created a project in Jira, with a Kanban board and a workflow with three states (Backlog, Rifinement, Done).
import com.atlassian.jira.bc.project.ProjectCreationData
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.AssigneeTypes
import com.atlassian.jira.project.type.ProjectTypeKey
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.canned.jira.admin.CopyProject
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger(getClass())
log.setLevel(Level.DEBUG)
@BaseScript CustomEndpointDelegate delegate
newClonedProject(httpMethod: "GET", groups: ["jira-administrators"]) { MultivaluedMap queryParams, String body ->
def project_key = queryParams.getFirst("CPBS ProjectKey") as String
def project_name = queryParams.getFirst("CPBS ProjectName") as String
if (!project_key) return Response.ok(new JsonBuilder([project_key: "", error: "Error in param project_key"]).toString()).build();
if (!project_name) return Response.ok(new JsonBuilder([project_key: "", error: "Error in param project_name"]).toString()).build();
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManager = ComponentAccessor.getProjectManager()
def destProjetKey = project_key
def destProjectName = project_name
def srcProjectKey = 'FXSPT'
def getSrcProjectObject = projectManager.getProjectByCurrentKey(srcProjectKey)
def targetKey = destProjetKey
def targetProjectName = destProjectName
if(getSrcProjectObject && targetKey && targetProjectName) {
def copyProject = new CopyProject()
def inputs = [
(CopyProject.FIELD_SOURCE_PROJECT) : srcProjectKey,
(CopyProject.FIELD_TARGET_PROJECT) : targetKey,
(CopyProject.FIELD_TARGET_PROJECT_NAME) : targetProjectName,
(CopyProject.FIELD_COPY_VERSIONS) : false,
(CopyProject.FIELD_COPY_COMPONENTS) : false,
(CopyProject.FIELD_COPY_ISSUES) : false,
(CopyProject.FIELD_COPY_DASH_AND_FILTERS): false,
//(CopyProject.FIELD_ORDER_BY) : "Rank", <-- no longer a valid option so I am commenting this out
]
def errorCollection = copyProject.doValidate(inputs, false)
if (errorCollection.hasAnyErrors()) {
log.debug("Couldn't create project: $errorCollection");
return Response.ok(new JsonBuilder([project_key: "", error: "Couldn't create project: $errorCollection"]).toString()).build();
} else {
def userManager = ComponentAccessor.getUserManager();