#!/bin/bash
# Configuration
BITBUCKET_URL="https://yourcompany.bitbucket.server"
PROJECT_KEY="CHE" # Replace with your project key
USERNAME="your_username" # Replace with your Bitbucket username
ACCESS_TOKEN="your_access_token" # Replace with your personal access token
# Directory to clone repositories
CLONE_DIR="./${PROJECT_KEY}_repositories"
mkdir -p "$CLONE_DIR"
# Fetch repositories using the Bitbucket API
REPOS=$(curl -s -u "$USERNAME:$ACCESS_TOKEN" \
"$BITBUCKET_URL/rest/api/1.0/projects/$PROJECT_KEY/repos?limit=100" | \
jq -r '.values[].links.clone[] | select(.name == "http").href')
# Clone each repository
echo "Cloning repositories from project $PROJECT_KEY..."
for REPO in $REPOS; do
REPO_NAME=$(basename "$REPO" .git)
echo "Cloning $REPO_NAME..."
git clone "$REPO" "$CLONE_DIR/$REPO_NAME"
done
echo "All repositories have been cloned into $CLONE_DIR."
curl -s -u "$USERNAME:$ACCESS_TOKEN" \
"$BITBUCKET_URL/rest/api/1.0/projects/$PROJECT_KEY/repos?limit=100" > api_response.json
for REPO in $REPOS; do
echo "Cloning from $REPO"
REPO_NAME=$(basename "$REPO" .git)
git clone "$REPO" "$CLONE_DIR/$REPO_NAME"
done
git -c http.sslVerify=false clone https://yourcompany.bitbucket.server/scm/project/repo1.git
Leave a Reply