Last active
July 29, 2024 09:07
-
-
Save eeichinger/babbdf99d8fe21fef8634d56f29defba to your computer and use it in GitHub Desktop.
script to clone all repositories in a bitbucket server (aka stash) project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script uses syntax for bitbucket server. | |
# For bitbucket cloud see https://confluence.atlassian.com/bitbucket/use-the-bitbucket-cloud-rest-apis-222724129.html | |
# | |
# Note: replace username, password and PROJECTNAME with your values | |
USERNAME=xxxx | |
PASSWORD=xxxx | |
PROJECTNAME=xxxxx | |
# jq syntax helpful links: | |
# - http://stackoverflow.com/questions/30601278/how-to-extract-keys-from-multiple-nested-arrays-using-jq | |
# - http://stackoverflow.com/questions/18592173/select-objects-based-on-value-of-variable-in-object-using-jq | |
curl -s -u $USERNAME:$PASSWORD https://bitbucket.example.com/rest/api/1.0/projects/$PROJECTNAME/repos/ \ | |
| jq -r '.values[].links.clone[] | select(.name=="ssh") | .href' \ | |
| xargs -I {} echo "git clone '{}'" > clone_repos.sh |
I've modified it a little bit.
curl -s -u "$ORG_USER:$ORG_PASS" "https://api.bitbucket.org/2.0/repositories/$ORG_TEAM?q=project.key%3D%22${ORG_PROJECT}%22&pagelen=100" \
| jq -r '.values[] | {slug:.slug, links:.links.clone[] } | select(.links.name=="ssh") | "git clone \(.links.href) \(.slug)"' | sort > clone-repos.sh
Make sure that you do not have more than 100 repos. In this case you need to add pagination, e.g. in a while-loop.
https://developer.atlassian.com/bitbucket/api/2/reference/meta/pagination
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Im really glad to hear it has helped another person out there 🥳
I created a issue on my project to track this issue
jensim/bitbucket_server_cli#21
Ill see to it as soon as i have some time to spare!