How to clone all projects of a group at once in GitLab?

后端 未结 15 1495
[愿得一人]
[愿得一人] 2020-12-23 02:02

In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?

15条回答
  •  旧巷少年郎
    2020-12-23 02:44

    Here is another example of a bash script to clone all the repos in a group. The only dependency you need to install is jq (https://stedolan.github.io/jq/). Simply place the script into the directory you want to clone your projects into. Then run it as follows:

    ./myscript   
    

    i.e.

    ./myscript group1 abc123tyn234 http://yourserver.git.com

    Script:

    #!/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/v3"
    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
    

提交回复
热议问题