You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I want to add multi user into one group, So I came with script below:
import com.atlassian.seraph.auth.DefaultAuthenticator
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import java.util.ArrayList
import java.util.List
import java.lang.String
def userUtil = ComponentAccessor.getUserUtil()
def groupManager = ComponentAccessor.getGroupManager()
def group = groupManager.getGroup("Group1")
def user
def names = "A,B,C".split(",")
def arrayLength = names.length
for (def i =0; i < arrayLength; i++){
user = userUtil.getUser(names[i])
groupManager.addUserToGroup(user,group)
}
But I got few error such as :
CannotCreateTransactionException: Could not create DirContext instance for transaction;
Please help me on this:
Try this:
import com.atlassian.jira.component.ComponentAccessor
def grpMgr = ComponentAccessor.getGroupManager()
def usrMgr = ComponentAccessor.getUserManager()
def targetGroup = grpMgr.getGroup("group name")
ArrayList usersToAdd = new ArrayList()
usersToAdd.addAll("usernameA","usernameB","usernameC")
for (int i = 0; i < usersToAdd.size(); i++){
grpMgr.addUserToGroup(usrMgr.getUserByName(usersToAdd[i]), targetGroup)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i got error as below:
org.springframework.transaction.CannotCreateTransactionException: Could not create DirContext instance for transaction; nested exception is org.springframework.ldap.CommunicationException
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Ivan,
I am starting error below:Can not find matching method com.atlassian.jira.user.UserManager#getUserByName(E)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def groupManager = ComponentAccessor.getGroupManager()
def usrMgr = ComponentAccessor.getUserManager()
ArrayList usersToAdd = new ArrayList()
def group = groupManager.getGroup("ABC_Users")
usersToAdd.addAll("A","B","C")
def user
for (int i = 0; i < usersToAdd.size(); i++){
user = (ApplicationUser) usrMgr.getUserByName(usersToAdd[i])
groupManager.addUserToGroup(user,group)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try This....
import com.atlassian.jira.component.ComponentAccessor
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
final String groupName = "GROUPA" // the group you want to add users
def group = ComponentAccessor.groupManager.getGroup(groupName) // user names of the users to add
final List<String> userToAdd = ["USR1", "USR2", "USR3"]
userToAdd.each {
def usertoadd = userManager.getUserByName(it)
if (!usertoadd) {
log.warn("User: $userToAdd doesn't exist")
return
}
if (ComponentAccessor.getGroupManager().getGroupsForUser(usertoadd).contains(group)) {
log.warn("User: $usertoadd.username already in the group: $groupName")
return
}
if(!group) {
log.warn("Group: $groupName doesn't exist")
} else {
userUtil.addUserToGroup(group, usertoadd)
log.warn("User: $usertoadd.username added to the $groupName")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.