ScriptRunner listener with UserCreatedEvent

Greg Fischer
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
February 21, 2025

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

 

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.9.13
TAGS
AUG Leaders

Atlassian Community Events