How to use "addUserToGroup" with Script Runner

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 += + "<br>" 


Here ( 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.

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

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



Suggest an answer

Log in or Join to answer
Community showcase
Louis De Jaeger
Posted Thursday in Off-topic

Friday fun: your best joke

Hi all Lets make this Friday fun really fun and post one (or more) of your best jokes! The joke can be about an Atlassian product, or just a really fun joke you want to share! I’m not the best j...

174 views 12 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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot