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 requesterApplicationUser projectLeadFinal = userManager.getUserByKey(projectLead.getKey())def projectDataBuild = new ProjectCreationData.Builder()//These all worked fineprojectDataBuild.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 ProjectCreationDataProject 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.ProjectTemplateManagerdef 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.ProjectTemplateManagerdef 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)
It looks like you're new here. Sign in or register to get started.