Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Use Scriptrunner to add multiple groups to a single user

David Lee May 16, 2022

I am new to Scriptrunner and I want to speed up the onboarding process by building some "persona" style scripts. For example,

User - "Project manager" requires "jira-user", "jira-software", "customer-share" groups

(I usually have 20-30 groups to add)

Is there a script I could use to run to add this in?

Thanks

David

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Nic Brough -Adaptavist-
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.
May 16, 2022

I think you can pretty much copy and paste the script over at https://library.adaptavist.com/entity/remove-specified-users-from-a-group - swapping the line at the end from removeUserFromGroup to addUserToGroup

0 votes
Ravi Sagar _Sparxsys_
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.
May 16, 2022

Hi @David Lee 

You would need to use group manager to do that. It is very simple script.

ComponentAccessor.groupManager.addUserToGroup(userToAdd, groupName)

I made a video and shared the script with some error handling in one of my video here.

Thanks,

Ravi

David Lee May 16, 2022

Thanks @Ravi Sagar _Sparxsys_ for the information, I am able to add single groups without error with this script.

 

What would I need to do to this to add in another group? Or do I just need to run it multiple times, changing the "group1" each time?
import com.atlassian.jira.component.ComponentAccessor
def userName = "User"
def groupNametoAdd = "group1"
def userToAdd = ComponentAccessor.getUserManager().getUserByName(userName)
def groupName = ComponentAccessor.getGroupManager().getGroup(groupNametoAdd)

ComponentAccessor.groupManager.addUserToGroup(userToAdd, groupName)
TAGS
AUG Leaders

Atlassian Community Events