Skip to content

Instantly share code, notes, and snippets.

@petarvucetin
Last active June 7, 2023 13:04
Show Gist options
  • Save petarvucetin/cd8c743205450eda50cb8c3e9dd0adad to your computer and use it in GitHub Desktop.
Save petarvucetin/cd8c743205450eda50cb8c3e9dd0adad to your computer and use it in GitHub Desktop.
Get all repositories from Azure DevOps bash
#!/bin/bash
rolesrepo="https://dev.azure.com/[org]/[project]/_apis/git/repositories?api-version=5.0"
personal_access_token="Username:zzzzzzzzz" #create PAT from secruity menu of your user profile.
user=""
base64AuthInfo="$(echo $personal_access_token | base64))"
#printf "The string\n[$personal_access_token]\nencodes into base64 as:\n[$base64AuthInfo]\n"
#curl $rolesrepo -H "Authorization=Basic $base64AuthInfo"
curl --request GET \
--url 'https://dev.azure.com/[org]/[project]/_apis/git/repositories?api-version=5.0' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic [base 64 encoded PAT token]' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Host: dev.azure.com' \
--header 'cache-control: no-cache' \
--output repos.json
#https://stedolan.github.io/jq/
sshUrl=`cat repos.json | jq "[.value[] | .sshUrl]"`
for row in $(echo "$sshUrl" | jq -r '.[]'); do
repo=`printf '%s\n' "${row##*/}"`
echo $repo
if [ ! -d "$repo" ]; then
git clone $row > /dev/null
fi
#switch directory to repo
pushd $repo > /dev/null
git fetch --prune
popd > /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment