To create an empty repository named some-example-repository
in a self-hosted GitLab server, I wrote the following bash method:
create_repository() {
repo_name="$1"
# load personal_access_token (from hardcoded data)
personal_access_token=$(echo "$GITLAB_PERSONAL_ACCESS_TOKEN" | tr -d '\r')
# Create the repository in the GitLab server
{ # try
output=$(curl -H "Content-Type:application/json" http://127.0.0.1/api/v4/projects?private_token="$personal_access_token" -d "{ \"name\": \"$repo_name\" }")
echo "output=$output"
true
} || { # catch
true
}
}
However, it is not functioning reliably, and occasionally it indicates a limit is reached. Hence, I would like to ask: how could I reliably create an empty GitLab repository in a self-hosted GitLab server using Bash and a personal access token?
CodePudding user response:
I would check the API limits to see if you are hitting that. Most likely, if you are doing this in a for
loop, you might need to sprinkle in some sleep 60
to slow things down.
I've created a hundred repos once before, but I was being paranoid and used sleep 300
between creations.