Created
July 28, 2025 13:02
-
-
Save J00MZ/08e0d1d891b48193e48d42ae19b39707 to your computer and use it in GitHub Desktop.
Create multiple Gitlab repos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
GITLAB_API="https://gitlab.com/api/v4" | |
TOKEN="${GL_ACCESS_TOKEN}" | |
GROUP_NAME="${GROUP_NAME:-'my-group'}" | |
REPO_NAMES=${REPO_NAMES_LIST:-'test-repo'} | |
get_group_id() { | |
local group_id=$(curl --silent --header "PRIVATE-TOKEN: $TOKEN" \ | |
"$GITLAB_API/groups?search=$GROUP_NAME" | jq '.[0].id') | |
echo $group_id | |
} | |
create_repo() { | |
local repo_name="$1" | |
local group_id="$2" | |
curl --header "PRIVATE-TOKEN: $TOKEN" \ | |
--header "Content-Type: application/json" \ | |
--data "{\"name\":\"$repo_name\", \"namespace_id\":$group_id}" \ | |
--request POST \ | |
"$GITLAB_API/projects" | |
echo "Repository '$repo_name' created in group '$GROUP_NAME'." | |
} | |
GROUP_ID=$(get_group_id) | |
if [ -z "$GROUP_ID" ]; then | |
echo "Error: Group '$GROUP_NAME' not found." | |
exit 1 | |
fi | |
for repo in "${REPO_NAMES[@]}" | |
do | |
create_repo "$repo" "$GROUP_ID" | |
sleep 2 # Add a small delay to avoid rate limiting | |
done | |
echo "All repositories created successfully in group '$GROUP_NAME'." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment