从gitlab group下批量clone repo的脚本

#!/bin/bash
#变量
#subgroup需要替换
subgroup='groupname';
#access_token需要替换,从gitlab右上角用户头像->Settings->Access Tokens获取
access_token='wvygNv3Vx2WUyP1X3QFA';
#获取项目列表接口地址
url="http://[yourServer:port]/api/v4/groups/${subgroup}?simple=true&membership=true&per_page=100";

#获取项目列表
curl --header "PRIVATE-TOKEN: ${access_token}" $url -o projects.txt;
#遍历项目列表,取projects中的项目,通过ssh方式克隆到当前目录下
jq ".projects[]" projects.txt | sed 's/,/\
/g' | grep 'ssh_url_to_repo' | sed 's/"/\
/g' | grep 'git@' | while read line;
do
	git clone $line $(echo $line | awk -F "${subgroup}/" '{print $2}' | awk -F '.git' '{print $1}');
done;
#删除projects.txt
rm -rf projects.txt
Share

You may also like...

发表回复

您的电子邮箱地址不会被公开。