Copy Project Template with Java API

andybandy89 April 20, 2020

Hi! 

I have created a Groovy Script to copy a project template in Jira Software Server with a Scriptrunner Postfunction. When I execute this script in Script Console everything works fine but when using it in the Postfunction it often happens that no permission scheme is assigned to the newly created project. Because of that lots a further issues occur. 

The only thing in the Log what I can find is this here:

2020-04-16 09:42:28,380 WARN [permission.DefaultPermissionSchemeManager]: No permission scheme is associated with project 'ABCD 1234'

 

This is the script what I have written to copy the project:

// Get Project Template
jiraAuthenticationContext.setLoggedInUser(adminUser)
def projectManager = ComponentAccessor.getProjectManager()
def projectTemplate = projectManager.getProjectObjByKey(tplKeyJira)

writeLog.info("Key: " + prjKey + ", Name: " + prjName + ", Template Jira: " + tplKeyJira + ", Template Wiki: " + tplKeyWiki)


// Create new Jira Project
def projectComponentManager = ComponentAccessor.getProjectComponentManager()
def projectService = ComponentAccessor.getComponent(ProjectService)

// Copy Project Template
Builder newProjectCreationDataBuilder = new Builder()
newProjectCreationDataBuilder.withKey(prjKey)
newProjectCreationDataBuilder.withName(prjName)
newProjectCreationDataBuilder.withLead(projectManagerValue)
newProjectCreationDataBuilder.build()
def newProjectCreationData = newProjectCreationDataBuilder.build()

Builder templateProjectCreationDataBuilder = new Builder()
templateProjectCreationDataBuilder.fromExistingProject(projectTemplate, newProjectCreationData)
def templateProjectCreationData = templateProjectCreationDataBuilder.build()

def projectValidateCreateResult = projectService.validateCreateProjectBasedOnExistingProject(adminUser, projectTemplate.getId(), templateProjectCreationData)
log.info("Create Project Validation - User: ${projectValidateCreateResult.getUser()}, Is Valid: ${projectValidateCreateResult.isValid()}")
log.warn("Warnings: ${projectValidateCreateResult.getWarningCollection().getWarnings()}")
log.error("Errors: ${projectValidateCreateResult.getErrorCollection()..getErrors()}")


Project createdProject
if (projectValidateCreateResult.isValid()){
createdProject = projectService.createProject(projectValidateCreateResult)
} else {
log.error(projectValidateCreateResult.errorCollection.getErrors())
throw new Exception(projectValidateCreateResult.errorCollection.getErrors().toString())
}

 

Does anybody has an idea why the permission scheme sometimes cannot be assigned? For me it would be logically if it would always does the same and not just sometimes...

 

Thanks and best regards

Andreas

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events