Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,501,492
Community Members
 
Community Events
180
Community Groups

How to add group to all projects

Edited

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.

3 answers

1 accepted

1 vote
Answer accepted

Ok, i found one way.
Take the ID of all projects and rewrite them in a text file
Next, create a script with the following code:

for (( i = 1; i < 8; i++ ))
do
key=$(sed -n $i"p" $1)
echo $key
key=${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

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 projects
import com.atlassian.jira.bc.projectroles.ProjectRoleService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleActor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.util.SimpleErrorCollection

def 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 name
def projectRole = projectRoleManager.getProjectRole("Administrators")

// Fetch group (case insensitive) and add to list (addActorsToProjectRole requires a list)
def group = groupManager.getGroup("testgroup").name
def list = new ArrayList<String>()
list.add(group)

// Fetch ALL Jira projects and loop add group to project role on each project
def projects = projectManager.getProjects()
for(item in projects) {
projectRoleService.addActorsToProjectRole(list,projectRole,item,ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE,errorCollection)
}
// Print errors in log
log.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!

Like Markus Fredén likes this

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.

Hi @Markus Fredén  Could you please explain this script, I am not sure which place I need to update my details. Thanks in advance!

Worked like a breeze and exactly what I was looking for.

Like Vasanthakumar Velusamy likes this

Hi @Ralph Kringhs ,

 

I am having the same requirement, could you please tell which code you have used and how.

 

Here is my requirement, I am having list of projects and its groups. I have to add those groups into projects. Thanks in advance.

I used @Markus Fredén 's ScriptRunner bit of code as shown in this thread

0 votes
josh Rising Star Sep 21, 2017

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>

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events