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