Last active
July 22, 2024 13:04
-
-
Save axi92/7731d7eb8011b95617fffd6f28f0a75c to your computer and use it in GitHub Desktop.
Clone all bitbucket repos from all projects
This file contains hidden or 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
#!/bin/bash | |
# generate a script ./clone-repos.sh from a list of repos fetched via Bitbucket API | |
# note: requires 'curl' and 'jq' to be installed | |
set -e | |
ONPREM_USER="" | |
ONPREM_PASS="" | |
URL="" | |
declare -a PROJECT_ARRAY=($(curl -s -u "$ONPREM_USER:$ONPREM_PASS" ${URL}/rest/api/1.0/projects/ | jq -r '.values[].key')) | |
echo "" > clone-repos.sh | |
for i in "${PROJECT_ARRAY[@]}" | |
do | |
echo "generate $i" | |
echo "# $i" >> clone-repos.sh | |
curl -s -u "$ONPREM_USER:$ONPREM_PASS" ${URL}/rest/api/1.0/projects/$i/repos/\?limit=1000 | jq -r --arg PROJECT $i '.values[] | {slug:.slug, links:.links.clone[], prefix:$PROJECT } | select(.links.name=="ssh") | "git clone \(.links.href) \(.prefix)_\(.slug)"' >> clone-repos.sh | |
done | |
chmod +x clone-repos.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment