Reputation: 479
How can I checkout all the git bitbucket repositories for a team using a bash script?
There are other questions for this topic however the bitbucket api mentioned in those answers does not exist anymore.
Upvotes: 4
Views: 9220
Reputation: 11
The following script is working well to download all repositories from Bitbucket.
UserName not email
Create App-password from Bitbucket
Run the script by sh script.sh
#!/bin/bash
user=username:password
curl -u $user 'https://api.bitbucket.org/2.0/user/permissions/teams?pagelen=100' > teams.json
jq -r '.values[] | .team.username' teams.json > teams.txt
for team in `cat teams.txt`
do
echo $team
rm -rf "${team}"
mkdir "${team}"
cd "${team}"
url="https://api.bitbucket.org/2.0/repositories/${team}?pagelen=100"
echo $url
curl -u $user $url > repoinfo.json
jq -r '.values[] | .links.clone[0].href' repoinfo.json > repos.txt
for repo in `cat repos.txt`
do
echo "Cloning" $repo
git clone $repo
done
cd ..
done
Upvotes: 1
Reputation: 6075
I made a simple script available here: https://github.com/mimo84/cloner It works similarly to the answer from Marcelo, however it uses the api on bitbucket to fetch them. It has jq as dependency as well.
Upvotes: 0
Reputation: 2874
I have written this small project in nodeJS, which supports GitHub and Bitbucket Cloud.
Upvotes: 0
Reputation: 22491
The following script will clone all repositories of a project:
for r in $(curl -s --user USER:PASS --request GET https://BITBUCKET-SERVER/rest/api/1.0/projects/PROJECT/repos | jq --raw-output '.values[].links.clone[].href')
do
git clone $r
done
Upvotes: 9