Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mason-splunk/06d9fe5bde41fbaca7d916ab2727839a to your computer and use it in GitHub Desktop.
Save mason-splunk/06d9fe5bde41fbaca7d916ab2727839a to your computer and use it in GitHub Desktop.
Generate a script to clone all repos within a specific project from bitbucket server and bitbucket cloud
# 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
echo -n '' > clone-repos.sh
chmod +x clone-repos.sh
ONPREM_USER=xxxxx
ONPREM_PASS=......
ONPREM_PROJECT=MYINTPROJ
curl -s -u "$ONPREM_USER:$ONPREM_PASS" https://bitbucket.mycompany.internal/rest/api/1.0/projects/$ONPREM_PROJECT/repos/\?limit=1000 | jq -r '.values[] | {slug:.slug, links:.links.clone[] } | select(.links.name=="ssh") | "git clone \(.links.href) \(.slug)-server"' >> clone-repos.sh
ORG_USER=yyyyyy
ORG_PASS=.......
ORG_PROJECT=MYCLOUDPROJ
ORG_TEAM=myteam
curl -s -u "$ORG_USER:$ORG_PASS" https://api.bitbucket.org/2.0/repositories/$ORG_TEAM/\?\q="project.key=\"$ORG_PROJECT\"" | jq -r '.values[] | {slug:.slug, links:.links.clone[] } | select(.links.name=="ssh") | "git clone \(.links.href) \(.slug)-cloud"' >> clone-repos.sh
# run the generated script
./clone-repos.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment