Hello,
I need to programmatically create a project via the Java API (version 8.22.5) for Jira Server. Here is my code:
// create a new Jira project with inputs from the requester
ApplicationUser projectLeadFinal = userManager.getUserByKey(projectLead.getKey())
def projectDataBuild = new ProjectCreationData.Builder()
//These all worked fine
projectDataBuild.withName(projectName)
projectDataBuild.withKey(projectKey)
projectDataBuild.withType("software")
projectDataBuild.withAssigneeType(AssigneeTypes.PROJECT_LEAD)
projectDataBuild.withLead(projectLeadFinal)
// The problem is here!!!
switch (projectType) {
case "Scrum":
projectDataBuild.withProjectTemplateKey("com.pyxis.greenhopper.jira:gh-simplified-scrum-classic")
break
case "Kanban":
projectDataBuild.withProjectTemplateKey("com.pyxis.greenhopper.jira:gh-simplified-kanban-classic")
break
default:
break
}
ProjectCreationData projectData = projectDataBuild.build() as ProjectCreationData
Project newProject = projectManager.createProject(projectLeadFinal,projectData)
Searching through the JavaDocs, I found: ProjectTemplateManager
You can output the keys for your environment with
import com.atlassian.jira.project.template.ProjectTemplateManager
def ptm = ComponentAccessor.getComponent(ProjectTemplateManager)
ptm.projectTemplates.collect{"$it.name = $it.key.key"}.join('<br>')
But then, rather than hardcoding the key, you could just look it up dynamically
import com.atlassian.jira.project.template.ProjectTemplateManager
def ptm = ComponentAccessor.getComponent(ProjectTemplateManager)
def projectTemplate = ptm.projectTemplates.find{it.name.startWith(projectType)}.key
/* ... */
def projectDataBuild = new ProjectCreationData.Builder()
projectDataBuild.withName(projectName)
projectDataBuild.withKey(projectKey)
projectDataBuild.withType("software")
projectDataBuild.withAssigneeType(AssigneeTypes.PROJECT_LEAD)
projectDataBuild.withLead(projectLeadFinal)
projectDataBuild.withProjectTemplateKey(projectTemplate.key)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.