Hi all,
I am trying to write a ScriptRunner listener to catch the UserCreatedEvent and add the new user to a Bitbucket group. I have tried:
def adminService = ComponentLocator.getComponent(UserAdminService)
def userName = event.getUser().name
Set<String> groupList = ["bitbucket-users"]
adminService.addUserToGroups(userName,groupList)
and
def directoryMgr = ComponentLocator.getComponent(DirectoryManager)
long dirID = directoryMgr.findDirectoryByName("Bitbucket Internal Directory")?.id
def userName = event.getUser().name
directoryMgr.addUserToGroup(dirID, userName, "bitbucket-users")
Both don't throw an error, there is nothing in the atlassian-bitbucket.log, but the user is not added to the bitbucket-users group. However, if I run the commands in the ScriptRunner Console, the user does get added to the group successfully. I even tried sleeping for 2 seconds before doing anything - same result, user is not added to the group.
What am I missing? Am I in a race condition of some sort where the user doesn't "really" exist yet?
Thanks,
-Greg
I just can say for the first example, I guess it is a permission problem. As from my understanding the triggered event script runs as the current user, who probably has no admin privileges in order to make that modification. So you would need to run it with admin privileges.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.