I am trying to streamline the creation of a project so that users without any jira experience can approve new projects. What I would like to happen is for a ticket to come in, and if a user hits approve on the workflow, it create the project, pulling certain custom fields from the issue. Here is the code I have, which executed correctly
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.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_18107")
String cFieldValue = issue.getCustomFieldValue(cField)
// the key for the new project
final String projectKey = "KENI"
// 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("software")
def creationData = new ProjectCreationData.Builder().with {
withName(projectName)
withKey(projectKey)
withDescription(projectDescription)
withLead(loggedInUser)
withProjectTemplateKey("com.pyxis.greenhopper.jira:basic-software-development-template")
withUrl(null)
withAssigneeType(AssigneeTypes.PROJECT_LEAD)
withType(projectTypeKey)
}.build()
final ProjectService.CreateProjectValidationResult projectValidationResult = projectService.validateCreateProject(loggedInUser, creationData)
assert projectValidationResult.isValid() : projectValidationResult.errorCollection
This code is a file on the server that a postfunction calls
My issue is:
When trying to find the project through jira UI, it is no where to be found, even from the sysadmin account. When trying to run this again, I get the error that a project with that key already exists.
I checked the DB, and the project does exist, I just cant find it in the UI.
Edit: I can also see it in the audit log, which looks like it completely successfully
Update: I was able to find it as the sysadmin because the logs pointed to it not having a permission scheme. So I guess my new question is why when I run this code as a postfunction from a file, does it not set a default permission scheme, but when I run it from Script Console it does?
Update 2: I ran the script again after finding and deleting the project. This time, it created the project and associated 2 permission schemes to it, which soft locked all of jira (hooray!). Had to restart jira and remove the duplicate permission scheme from the DB.