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

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!

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

 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Friday in Off-topic

Friday Fun: Dry T-Shirt Competition - What's your BEST (Atlassian) T-Shirt!?

[Note: So it was my turn for Friday Fun and sadly I was sick thanks to rubbish sinus infection... so apologies to most of Europe and Asia for the delayed post. However, I finally got out of bed for t...

142 views 8 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you