Import users to Bitbucket from an external user directory

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

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

Solution

Solutions

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.

1 2 3 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:

users.txt

1 2 3 4 user_name user_name display_name email_address bstuart bstuart bstuart bstuart@noemail.com rgoody rgoody "ryan goody" bee_phats@yahoo.com Pirates Pirates "Fletcher Christian" fchristi@royalnavy.mod.uk

Here is an example script to import your users and assign their user name as the password by default.

AddUsers.sh

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #!/bin/bash ABORT="N" case "$1" in "") echo "Usage: AddUsers.sh Admin_UserName Admin_Password" ABORT="Y";; * ) USERNAME=$1;; esac if [ "$ABORT" == 'N' ]; then case "$2" in "") echo "Usage: AddUsers.sh Admin_UserName Admin_Password" ABORT="Y";; * ) PASSWORD=$2;; esac fi if [ "$ABORT" == 'N' ]; then clear 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 fi

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.

Updated on April 15, 2025

Still need help?

The Atlassian Community is here for you.