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

How to use "addUserToGroup" with Script Runner

Hello,
i want to use the script runner to add users to group.
I found this script for showing the users who are not in a group:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtilUserUtil userUtil = ComponentAccessor.getUserUtil()
result = ''

userUtil.getUsers().findAll {
	userUtil.getGroupsForUser(it.getName()).size() == 0}
	.each { u -> result += u.name + "<br>" 
	}
result

 

Here (https://docs.atlassian.com/jira/latest/com/atlassian/jira/security/groups/GroupManager.html) is see the method "addUserToGroup".
Is it possible to help me for programming the additional code, to add users to an existing group?

Would me help very much.
Thanks

2 answers

Suggest an answer

Log in or Sign up to answer
4 votes
Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Feb 04, 2015

It should be something like that:

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()


def group = groupManager.getGroup("Group1")

userManager.getAllUsers().each {
    user -> groupManager.addUserToGroup(user,group)
}

This code add all users to Group1

I needed to add more than 1000 users to a group, with a conditional before the function it worked like magic for me, Thanks!

Didn't work for me, it get the error below. ScriptRunner version 5.6.15.1-p5 

 

scripterror.png

Hi Brad, Replace

>

to

>

All codes we post here have this kind of character scape... 

user -> groupManager.addUserToGroup(user,group)

Like Brad Butchers likes this

Thanks Danilo_Lima :)

Thanks for your answer. It was to define the group before :)

 

 

TAGS
AUG Leaders

Atlassian Community Events