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

This widget could not be displayed.

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!

This widget could not be displayed.

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

 

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 50m ago in United States

Local Atlassian Research Workshop opportunity on Sep. 28th

We're looking for participants for another workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sh...

8 views 0 0
View post

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