1. Get by groups API (Recommend)
Get All pages of the subproject:
GITLAB_API="https://<SITE>/api/v4/groups/<GROUP_NAME>/projects?include_subgroups=true&per_page=100"
PRIVATE_TOKEN="<your token>"
for ((page=1; ; page+=1)); do
# Use cURL to get all projects
response=$(curl --silent --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" "$GITLAB_API&page=${page}")
if [ $(jq length <<< "$response") -eq 0 ]; then
break
fi
# Use jq to parse JSON response, extract project names, write as csv
names=$(echo "$response" | jq -r '.[] | [ .path_with_namespace] | @csv')
# Print project names to console
echo "$names"
done
Gitlab docs is here.
2. Get by project API
Get all project and filter them.
GITLAB_API="https://<SITE>/api/v4/projects?per_page=100"
PRIVATE_TOKEN="<your token>"
for ((page=1; ; page+=1)); do
# Use cURL to get all projects
response=$(curl --silent --header "PRIVATE-TOKEN: $PRIVATE_TOKEN" "$GITLAB_API&page=${page}")
if [ $(jq length <<< "$response") -eq 0 ]; then
break
fi
# Use jq to parse JSON response, extract project names, write as csv
names=$(echo "$response" | jq -r '.[] | select(.path_with_namespace | startswith("<GROUP_NAME>")) | [ .path_with_namespace] | @csv')
# Print project names to console
echo "$names"
done