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

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Programmatically create Stash GIT repos

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 Jun 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"}'

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

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

seb Atlassian Team Sep 04, 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.

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.

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
Community showcase
Published in Atlassian Community Events

Hello from city #68 on the road!

Hello from my sixty-eighth city in a long-term RV trip I started in 2015!  I've traveled all over the US staying in different cities and states for just a few days up to many months. This week I...

44 views 1 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you