Forums

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

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

 

1 answer

0 votes
Michael Aglas
Contributor
September 19, 2025

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.

Suggest an answer

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

Atlassian Community Events