Suppose we have a group named as groupA in gitlab, under which we have sub folder structure, and there are multiple projects under a folder.
We wish to clone all the projects under folder.
This can be done using gitlab api. Like below -
1) You should have Token for authentication.
TOKEN="J612a-xUoMxxcerssRe31_"
2) API URL to subfolder that should give you group id.
API_URL1="https://<gitlab.server.com>/api/v4/groups?search=groupA /dir1/dir2/dir3/dir4"
3) Use below to get group id -
GROUP_ID=$(curl --silent --header "Private-Token: $TOKEN" "$API_URL1" | jq -r '.[].id')
4) Now you can fetch and clone all projects by using below -
API_URL2="https://<gitlab.server.com>/api/v4/groups/$GROUP_ID/projects"
# Fetch repositories list
REPOS=$(curl --silent --header "Private-Token: $TOKEN" "$API_URL2" | jq -r '.[].http_url_to_repo')
# Clone each repository
for REPO in $REPOS; do
git clone $REPO
done
5) Save above file as unix script and execute via git bash. This should download all projects.
Comments
Post a Comment