Hello All,
For the life of me I cannot find a simple example on how to create a project using JIRA's java api. I am getting my feet wet into the api and groovy so I don't know much. I am very familiar with the REST api however I do not want to use that because it is limited in terms of setting schemes.
import com.atlassian.jira.user.ApplicationUser 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.Project import com.atlassian.jira.util.ErrorCollection //def user = ComponentAccessor.getUserManager().getUserByName('admin') ApplicationUser user = ComponentAccessor.getUserManager().getUserByName('admin') ProjectCreationData.Builder builder = new ProjectCreationData.Builder() builder.withKey('KEY123').withName('KEY123').withLead(user) ProjectCreationData data = builder.build() Project validatedProject = ComponentAccessor.getProjectManager().createProject(user,data);
The error I get is:
java.lang.IllegalStateException at com.google.common.base.Preconditions.checkState(Preconditions.java:158) at com.atlassian.jira.project.DefaultProjectManager.createProject(DefaultProjectManager.java:177) at com.atlassian.jira.project.CachingProjectManager.createProject(CachingProjectManager.java:143) at com.atlassian.jira.project.ProjectManager$createProject.call(Unknown Source) at test.run(test.groovy:19)
Will using scriptrunner and the java api allow me to set more complicated schemes like issue, screen, workflow etc..?
Thanks,
Maxx
EDIT:
This is the correct answer thanks to Daniel, at the time of this post, this answer is compliant with api 7.3.6
import com.atlassian.jira.bc.project.ProjectCreationData.Builder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.Project
import com.atlassian.jira.bc.project.ProjectService
def user = ComponentAccessor.getUserManager().getUserByName('admin')
def projectService = ComponentAccessor.getComponent(ProjectService)
Builder builder = new Builder()
builder.withKey('MAXX23').withName('MAXX23').withLead(user).withDescription('helloworld').withType('business')
def data = builder.build()
def projectResult = projectService.validateCreateProject(user, data)
Project prj = projectService.createProject(projectResult)
return 'finished'
Hi Maxxrdrgz.
To create a project in Jira you firrst need to validate the creation of the project. Then you need to create the project using the validation results of that first step.
This is how you would create a project with scriptrunner:
import com.atlassian.jira.bc.project.ProjectService
def static projectService = ComponentAccessor.getComponent(ProjectService)
def createProjectValidationResult = projectService.validateCreateProject(currentUser, projectName, key, null, currentUser.name, null, AssigneeTypes.PROJECT_LEAD) project = projectService.createProject(createProjectValidationResult)
The variabels passed onto the first function come from another script, so do not take the values literally, you can have a read on the official documentation here.
If I can help you any further, please let me know.
Cheers!
DYelamos
Apologies:
You get it like this
def static projectService = ComponentAccessor.getComponent(ProjectService)
I updated my answer to better reflect what you need to do.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Daniel , Maxxrdrgz
When i tried the above code it is giving me an error :
java.lang.IllegalStateException: You can not create a project with an invalid validation result. at com.atlassian.jira.bc.project.DefaultProjectService.createProjectInternal(DefaultProjectService.java:382) at com.atlassian.jira.bc.project.DefaultProjectService.createProject(DefaultProjectService.java:373) at com.atlassian.jira.bc.project.ProjectService$createProject$0.call(Unknown Source) at Script6.run(Script6.groovy:18)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That means that the validation is getting a fail. Which means that you are feeding the wrong data into the creation of the validation.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello All,
when creating the new project can I set to it another existing workflow because the builder takes the existing one in the default workflow scheme.
best regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.