Skip to content

Instantly share code, notes, and snippets.

@timothystewart6
Last active October 1, 2018 01:02
Show Gist options
  • Save timothystewart6/cc2c80ecac615bfd45f094fcc91e0abf to your computer and use it in GitHub Desktop.
Save timothystewart6/cc2c80ecac615bfd45f094fcc91e0abf to your computer and use it in GitHub Desktop.
clone all gitlab repos for an org
# install
# macOS brew install jq
# ubuntu/debian sudo apt-get install jq
# chmod +x clone_all.sh
# gitlab api token https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
# usage:
# ./clone_all.sh YOUR_GITLAB_ORG_NAME YOUR_GITLAB_API_TOKEN https://gitlab.com
#!/bin/bash
if command -v jq >/dev/null 2>&1; then
echo "jq parser found";
else
echo "this script requires the 'jq' json parser (https://stedolan.github.io/jq/).";
exit 1;
fi
if [ -z "$1" ]
then
echo "a group name arg is required"
exit 1;
fi
if [ -z "$2" ]
then
echo "an auth token arg is required. See $3/profile/account"
exit 1;
fi
if [ -z "$3" ]
then
echo "a gitlab URL is required."
exit 1;
fi
TOKEN="$2";
URL="$3/api/v4"
PREFIX="ssh_url_to_repo";
echo "Cloning all git projects in group $1";
GROUP_ID=$(curl --header "PRIVATE-TOKEN: $TOKEN" $URL/groups?search=$1 | jq '.[].id')
echo "group id was $GROUP_ID";
curl --header "PRIVATE-TOKEN: $TOKEN" $URL/groups/$GROUP_ID/projects?per_page=100 | jq --arg p "$PREFIX" '.[] | .[$p]' | xargs -L1 git clone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment