Created
February 24, 2020 08:58
-
-
Save imchao9/3ebfac1bdfe4c72709763e9e061def7c to your computer and use it in GitHub Desktop.
gitlab clone all projects
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
#!/usr/bin/env bash | |
# should install jq first, for mac:brew install jq | |
# Documentation | |
# https://docs.gitlab.com/ce/api/projects.html#list-projects | |
NAMESPACE="<Your NAMESPACE Name>" | |
BASE_PATH="https://xxx.xxx.cn" | |
PROJECT_SEARCH_PARAM="" | |
PROJECT_SELECTION="select(.namespace.full_path | contains(\"$NAMESPACE\"))" | |
INCLUDE_SUBGROUPS="true" | |
#below use git@xxx to git clone | |
PROJECT_PROJECTION="{ "path": .path, "git": .ssh_url_to_repo }" | |
#below use http:// to git clone | |
#PROJECT_PROJECTION="{ "path": .path, "git": .http_url_to_repo }" | |
GITLAB_PRIVATE_TOKEN="xxx" | |
FILENAME="repos.json" | |
trap "{ rm -f $FILENAME; }" EXIT | |
curl -s "${BASE_PATH}api/v4/projects?private_token=$GITLAB_PRIVATE_TOKEN&search=$PROJECT_SEARCH_PARAM&include_subgroups=true&per_page=999" \ | |
| jq --raw-output --compact-output ".[] | $PROJECT_SELECTION | $PROJECT_PROJECTION" > "$FILENAME" | |
while read repo; do | |
THEPATH=$(echo "$repo" | jq -r ".path") | |
GIT=$(echo "$repo" | jq -r ".git") | |
if [ ! -d "$THEPATH" ]; then | |
echo "Cloning $THEPATH ( $GIT )" | |
git clone "$GIT" --quiet & | |
else | |
echo "Pulling $THEPATH" | |
(cd "$THEPATH" && git pull --quiet) & | |
fi | |
done < "$FILENAME" | |
wait |
#! /bin/bash
GITLAB_HOST="xxx.xxx.cn"
GROUP_ID=7
PRIVATE_TOKEN=""
INCLUDE_SUBGROUPS=true
for repo in $(curl "https://${GITLAB_HOST}/api/v4/groups/${GROUP_ID}/projects?private_token=${PRIVATE_TOKEN}&include_subgroups=true" | jq .[].ssh_url_to_repo | tr -d '"');
do git clone $repo;
done;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ghorg clone 7 --scm gitlab --preserve-dir