How to import users into Bitbucket Server from an external user directory

Still need help?

The Atlassian Community is here for you.

Ask the community


Outages sometimes make it necessary to move users from an external user directory like JIRA or LDAP into Stash to prevent interruption. 


Unfortunately, we don't have a great option to import users into the internal directory right now. We currently have a feature request you can watch, follow and vote on here: BSERV-7887 - Getting issue details... STATUS

If you only have a few users that you need to import you can do so manually from the UI or via REST API. 

Importing with the UI


To make these changes manually, please use the following steps: 


  1. Identify the users that you need to copy and note their attributes: user name and full name.
  2. Disable the external user directory in Administration >> User Directories.
  3. Go to Administration >> Users and Add user at the top right. 
  4. Manually add all the noted users in this way. 
  5. Enable the external directory again.


When you reenable the external directory Bitbucket Server should now label these users in the user list as part of the "Bitbucket Server Internal" directory.


Importing with REST API


If you have more than a few users to add, the quickest way to add them may be to write a script utilizing the REST API. The creation of such scripts can by accomplished in many ways and you can find an example of this in the our article How to add users to Bitbucket Server using Rest API.

Script and Tabulated Text File

You can create a tabulated text file from querying the Bitbucket Server Database with something similar to the below.

SELECT user_name, user_name, display_name, email_address
FROM BSERV.cwd_user
Where directory_id like '<directory_id>'

This will generate the following text file:

user_name	user_name	display_name	email_address
bstuart	bstuart	bstuart
rgoody	rgoody	"ryan goody"
Pirates	Pirates	"Fletcher Christian"

Here is an example script to import your users and assign their user name as the password by default.
case "$1" in
  "") echo "Usage: Admin_UserName Admin_Password"
  * ) USERNAME=$1;;
if [ "$ABORT" == 'N' ]; then
  case "$2" in
    "") echo "Usage: Admin_UserName Admin_Password"
    * ) PASSWORD=$2;;
if [ "$ABORT" == 'N' ]; then
  while read -r a b c d; do
    echo "User: $a"
    curl -u $USERNAME:$PASSWORD -X POST -H "Content-Type: application/json" "http://localhost:7990/bitbucket/rest/api/1.0/admin/users?name=$a&password=$b&displayName=$c&emailAddress=$d&addToDefualtGroup=true&notify=false"
  done < users.txt

This is only meant as an example and is not supported. There is no error checking or handling if users already exist in Bitbucket Server.

There are ways of editing the database directly in order to add users as well, but this is riskier and is not recommended.

Last modified on Jan 24, 2020

Was this helpful?

Provide feedback about this article
Powered by Confluence and Scroll Viewport.