How do I set certain groups to a new JIRA project as part of a specific Project Role using JIRA API?

Priya_Nair November 1, 2019

I'm using JIRA 8.0.3. We had a need to programmatically create JIRA projects from an existing template which would be triggered in a workflow transition as part of a new Issue Type. I was able to do this successfully by using the JIRA API from a post-function inline script (ScriptRunner).

As a next step, I need to add groups to specific Project Roles for the newly created JIRA project. Please bear in mind that the groups would be unique for each new JIRA project. I did look into JIRA API about ProjectRole, ProjectRoleManager and ProjectRoleService. However, the method addActorsToProjectRole expects a Collection of Actors. In my case, the group name to add would be a String. So I'm not sure how to proceed.

Here is my existing code (projKey, projName, projLead are user-entered information; origUser is the user who is person clicking on the workflow transition to create the project) -

Builder builder = new Builder()
builder.withKey(projKey.toString()).withName(projName.toString()).withLead(projLead)
def data = builder.build()
// Validate whether logged in origUser  has privileges to create the project from existing Project Template

def projectResult = projectService.validateCreateProjectBasedOnExistingProject(origUser, PROJECT_TEMPLATE_PID, data)

Project prj = projectService.createProject(projectResult)

The above snippet works for creating a new project with the existing project template id.

However, I'm stuck now trying to add groups to the project for specific project roles. I have looked at the below documentation but can only find addActorsToProjectRole (as mentioned above) and nothing related to adding users or groups to a project role for a project.

https://docs.atlassian.com/software/jira/docs/api/8.0.3/com/atlassian/jira/bc/projectroles/ProjectRoleService.html

0 answers

Suggest an answer

Log in or Sign up to answer