-
-
Save behrica/7127cdf1117d4b6b39fada1940cffa3d to your computer and use it in GitHub Desktop.
Get all repositories from Azure DevOps bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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