Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Programmatically create Stash GIT repos

damon hatchett June 28, 2012

Is there a way to programmatically create GIT repos in Stash (running Postgres). I need to create 40 odd blank starters in a central model, I have the list of names I want to use.

2 answers

1 accepted

9 votes
Answer accepted
seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 28, 2012

Definitely.

You can use the Stash REST apis to do this. If you would like to see all the REST endpoints, please have a read through the REST apis or install the REST api browser plugin in Stash.

The REST endpoint you will want to use is as follows:

curl -u user:pass -X POST -H "Accept: application/json"  -H "Content-Type: application/json" "http://stash/projects/QA/repos/" -d '{"name": "Repository Name"}'

nweiler2 September 3, 2012

What does it mean if I get an error message stating the following:

"{"errors":[{"context":nul,l...]}

seb
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 4, 2012

It means that your request is malformed. Unfortunately it seems that Stash is not providing a good error message in this exact circumstance. If you provide the details of the request you are creating (headers, url, content) then I can look into it and fix your request and also make sure we do better error handling for this case.

Aries McRae November 3, 2013

The initial post by Seb worked for me as is.

Just don't forget to put /repos/ at the end of your stash project name. eg.

http://yourstashserverhost/projects/yourstashprojectname/repos/

Initially, I only had

http://yourstashserverhost/projects/yourstashprojectname/

so it didn't work.

0 votes
nweiler2 September 4, 2012

Edit: It now seems to be working with wget but not curl. Clearly this is just a curl issue so I think I will just drop it and use wget. Thanks again for the help.

Thanks, Seb. I actually managed to create a repo by manually creating an http request through a proxy. Here is the request that worked:

POST /rest/api/1.0/projects/[Project Name]/repos HTTP/1.1
Host: [hostname]
Connection: keep-alive
Authorization: Basic [user:pass (Base64)]
Content-Length: 29
Cache-Control: max-age=0
Origin: https://[hostname]
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1
Content-Type: application/json
Accept: application/json
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3

{"slug":"test","name":"test"}
curl -k -X POST -H "Host: [hostname]" -H "Connection: keep-alive" -H "Authorization: Basic [user:pass(Base64)]" -H  "Content-Length: 29" -H "Cache-Control: max-age=0" -H "Origin: https://[hostname]" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.83 Safari/537.1" -H "Content-Type: application/json" -H "Accept: application/json" -H "Accept-Encoding: gzip,deflate,sdch" -H "Accept-Language: en-US,en;q=0.8" -H "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3" --data {"slug":"test", "name":"test"} https://[hostname]/rest/api/1.0/projects/[projectName]/repos/
wget --no-check-certificate --header='Host: [hostname]' --header 'Connection: keep-alive' --header 'Authorization: Basic [user:pass(Base64)]' --header 'Content-Type: application/json' --header 'Accept: application/json' --post-data='{"slug":"test", "name":"test"}' https://[hostname]/rest/api/1.0/projects/[projectName]/repos/

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events