脚本定制gitlab官方api获取项目组下的所有项目

脚本说明

通过gitlab官方api接口获取项目组下的所有项目的ssh_git连接并同步项目仓库

#!/bin/bash
url='https://gitee.xxxxx.cn'
dir=/usr/src/redmine/git-repo
group_id='69'
token='2dskWweijirdrrm9UERv'

cd ${dir}

#获取所有项目ssh_url_to_repo
curl -s "${url}/api/v4/groups/${group_id}/projects?private_token=${token}&per_page=99999" | grep -o '"ssh_url_to_repo":[^ ,]\+' | awk -F '"' '{print $4}' > ${dir}/repo.txt 

#获取本地已同步的项目名
ls ${dir} | grep '.git' > ${dir}/localrepo.txt

#同步本地没有的项目
for repo in `cat ${dir}/repo.txt`

do
  #完整的ssh_url_to_repo
  ssh_url=${repo}
  #截取项目名
  repo=${repo##*/}
  #判断本地是否存在该项目
  num=`grep -c $repo ${dir}/localrepo.txt`
  #echo "$num $repo"
  if [ $num -eq 0 ];then
    echo "start clone mirror $repo"
    #同步项目
    git clone --mirror ${ssh_url} --config core.sshCommand="ssh -i ${dir}/.ssh/id_rsa"
   echo "clone end"
  fi


done


你可能感兴趣的:(shell,gitlab)