Hi! Can anybody help me pls? How can i add a group to the role in all projects via REST API? Since there are a lot of projects and it is very difficult to do this by hands.
I have a jira version 6.3.8
Thanks.
Ok, i found one way.Take the ID of all projects and rewrite them in a text fileNext, create a script with the following code:
for (( i = 1; i < 8; i++ ))dokey=$(sed -n $i"p" $1)echo $keykey=${key%$'\r'}curl -x http://YourProxyServer:3128/ -i -H 'Content-Type: application/json' -X POST -d '{"group": ["YourGroup"]}' -u user:password https://jira_url/rest/api/latest/project/${key}/role/{roleid}done
When I need to do this, I open in excel the list of project keys (copy and paste from admin page), then build a lot of curl commands that put a group in a role for a single project.
Repeat this command for every project:
curl -i -H 'Content-Type: application/json' -X POST -d '{"group": ["GroupName"]}' -u username:password https://<jiraurl>/rest/api/latest/project/<projectKey>/role/<roleId>
Hi @kyco4ektopta
If you don't want to do this via REST API there's a way to do it using the ScriptRunner "Script Console";
//// Script to add group to project role in ALL Jira projectsimport com.atlassian.jira.bc.projectroles.ProjectRoleServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.security.roles.ProjectRoleActorimport com.atlassian.jira.security.roles.ProjectRoleManagerimport com.atlassian.jira.util.SimpleErrorCollectiondef groupManager = ComponentAccessor.getGroupManager()def projectManager = ComponentAccessor.getProjectManager()def projectRoleService = ComponentAccessor.getComponent(ProjectRoleService)def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)def errorCollection = new SimpleErrorCollection()// Fetch project role object by namedef projectRole = projectRoleManager.getProjectRole("Administrators")// Fetch group (case insensitive) and add to list (addActorsToProjectRole requires a list)def group = groupManager.getGroup("testgroup").namedef list = new ArrayList<String>()list.add(group)// Fetch ALL Jira projects and loop add group to project role on each projectdef projects = projectManager.getProjects()for(item in projects) {projectRoleService.addActorsToProjectRole(list,projectRole,item,ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE,errorCollection) }// Print errors in loglog.warn(errorCollection)
Then you don't have to do those manual steps in excel.
Obviously, this requires you to have ScriptRunner installed. Just run the code in the SR "Script Console" but make sure to test it in a test environment first!
Best regards,
Markus Fredén
This worked perfectly for me. Thank you Markus!
Hi @Markus Fredén,
with above script if i would like to do only for few projects based on list?
Thanks
@Markus Fredén -
def projects = projectManager.getProjects()
The above code is giving me all projects in jira.
If we have only 10 projects to be updated, how can we define the list? I have the names of all 10 projects.
--Swathi.
It looks like you're new here. Sign in or register to get started.