Automate a gitlab project creation with curl.

Describe some of needed steps to create a project for a specific user in[1]

This steps consist mainly in getting the user_id from a user_name with the appropriate curl GET :user_id command. And with this id, to use another curl POST :projects command to create a project for the user identified by this id. Note the GET and POST curl commands embedded in the alias :

GET.gitlab() {
curl -s --header "PRIVATE_TOKEN=blabla"

POST.gitlab() {
curl -s -X POST --header "PRIVATE_TOKEN=blalba"

So you can ...

  1. Get the user_id with you user_name: /users?username=user_name
$ user_id=$(./GET.gitlab /users?username=fredmj | grep "\"id\":" | sed -e's/[^[:digit:]]*//g')

2. Create the project my_project for the user user_name

$DESCRIPTION="This is a short description on one paragraph without any formating tag. For more specifics informations about the project, please use the file with markdown formating";./POST.gitlab ${id}/projects?name=`my_project`\&description=$(echo $DESCRIPTION | sed -e\'s/ /\%20/g\')

3. Note you may use the JSON formating for your inputs. With the -H "Content-Type: applications/json" and the --data {"key": "value"} way or even with the -d @<file.json>

4. Note also the json.tool python module which is useful for checking humanly the json output format :

curl -X POST bla bla | python -m json.tool

You need to be gitlab admin to perform this operation. So this will not work on you even with your owned project. Instead just use the form :

curl -X POST -H "Private-Token: blabla"<PROJECT_NAME>\&description=THis%20my%20usual%20Description
Afficher les commentaires