Skip to main content
Example scripts
arrow icon
To homepage
Jira
Data centre icon
Data Center

Automate Your Project Creation in Jira

Created 1 year ago, Updated 4 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira (8.0 - 8.14)
compatibility bullet
ScriptRunner For Jira (6.18.0)
Language |
groovy
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

// the key for the new project
final String projectKey = "AAA"

// the name of the new project
final String projectName = "A new Project"

// the description for the new project - optional
final String projectDescription = "project for testing"

def projectService = ComponentAccessor.getComponent(ProjectService)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// available project type keys: business | software | service_desk
def projectTypeKey = new ProjectTypeKey("business")

def creationData = new ProjectCreationData.Builder().with {
    withName(projectName)
    withKey(projectKey)
    withDescription(projectDescription)
    withLead(loggedInUser)
    withUrl(null)
    withAssigneeType(AssigneeTypes.PROJECT_LEAD)
    withType(projectTypeKey)
}.build()

final ProjectService.CreateProjectValidationResult projectValidationResult = projectService.validateCreateProject(loggedInUser, creationData)
assert projectValidationResult.valid : projectValidationResult.errorCollection

projectService.createProject(projectValidationResult)
Having an issue with this script?
Report it here