Skip to content

Instantly share code, notes, and snippets.

@truongngoclinh
Created July 24, 2019 12:32
Show Gist options
  • Save truongngoclinh/5ef7fd9e310ef693847d2b3fad6fe29d to your computer and use it in GitHub Desktop.
Save truongngoclinh/5ef7fd9e310ef693847d2b3fad6fe29d to your computer and use it in GitHub Desktop.
Clone all projects in gitlab group
#!/usr/bin/env bash
BASE_PATH="your domain"
GITLAB_PRIVATE_TOKEN="your private token"
if [ -z "$1" ]
then
echo "group name is required."
exit 1;
fi
GROUP_NAME="$1"
if [ -z "$GITLAB_PRIVATE_TOKEN" ]; then
echo "Please set the environment variable GITLAB_PRIVATE_TOKEN"
echo "See ${BASE_PATH}profile/account"
exit 1
fi
FIELD_NAME="ssh_url_to_repo"
echo "Cloning all git projects in group $GROUP_NAME";
REPO_SSH_URLS=`curl -s "${BASE_PATH}api/v4/groups/$GROUP_NAME/projects?private_token=$GITLAB_PRIVATE_TOKEN&per_page=999" \
| grep -o "\"$FIELD_NAME\":[^ ,]\+" | awk -F'"' '{print $4}' | grep $GROUP_NAME`
for REPO_SSH_URL in $REPO_SSH_URLS; do
THEPATH=$(echo "$REPO_SSH_URL" | awk -F'/' '{print $NF}' | awk -F'.' '{print $1}')
if [ ! -d "$THEPATH" ]; then
echo "Cloning $THEPATH ( $REPO_SSH_URL )"
git clone "$REPO_SSH_URL" &
#git clone "$REPO_SSH_URL" --quiet &
else
echo "Pulling $THEPATH"
(cd "$THEPATH" && git pull) &
#(cd "$THEPATH" && git pull --quiet) &
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment