Skip to content

Instantly share code, notes, and snippets.

@axi92
Created March 19, 2024 14:04
Show Gist options
  • Save axi92/7731d7eb8011b95617fffd6f28f0a75c to your computer and use it in GitHub Desktop.
Save axi92/7731d7eb8011b95617fffd6f28f0a75c to your computer and use it in GitHub Desktop.
Clone all bitbucket repos from all projects
#!/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 '.values[] | {slug:.slug, links:.links.clone[] } | select(.links.name=="ssh") | "git clone \(.links.href) \(.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