Import users to Bitbucket from an external user directory
プラットフォームについて: Data Center - この記事は、Data Center プラットフォームのアトラシアン製品に適用されます。
このナレッジベース記事は製品の Data Center バージョン用に作成されています。Data Center 固有ではない機能の Data Center ナレッジベースは、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。
*Fisheye および Crucible は除く
目的
Outages sometimes make it necessary to move users from an external user directory like JIRA or LDAP into Stash to prevent interruption.
ソリューション
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:
- Identify the users that you need to copy and note their attributes: user name and full name.
- Disable the external user directory in Administration > User Directories.
- Go to Administration > Users and Add user at the top right.
- Manually add all the noted users in this way.
- 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 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.
#!/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¬ify=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.