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

how to get repository list for a stash project?

Jennifer Schuch Sep 24, 2013

Stash project has 65+ repositories (modules) and growing. To not adjust the build process everytime a new repository is added, is there a way to query the stash project to get a listing of repositories to then input to a script to clone each at build time?

4 answers

1 accepted

0 votes
Answer accepted
Andrew Milne Sep 25, 2013

I'd suggest writting a script to do the query and then filter the results down and print the output list in the format you require for your build system.

For example: You could write a get_repo_list script that takes a project name (or ~<user>) and prints all the repository slugs or the clone urls or some other simple list.

There some example code on writing oath capable REST clients for Atlassian products at:

https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples

The PERL example was written with Stash in mind (Disclaimer: I wrote it) and should be easy to use it to make such a query, parse the JSON structure into perl and then iterate over it pulling out the field you want (just make sure to handle the whole paged API thing or you only get some of the results).

0 votes

Hi there Jennifer,

You can use the REST API to achieve that.

Are all repositories created by the same user?

There are some examples with the REST API that can he useful for you.

Please check them here:

https://answers.atlassian.com/questions/193504/stash-pr-rest-api-for-user-repositories

The rest api for Stash core can be found here: https://developer.atlassian.com/static/rest/stash/2.7.2/stash-rest.html.

Regards,

Celso Yoshioka

Jennifer Schuch Sep 25, 2013

Hi Celso,

I've been playing around with the REST API using the browser plugin...is there a way to limit these results to only being the "slug"?? I'm trying to use curl to get this information in a way to pass to my git clone statements.

The repos will not be created by the same user.

I also found this https://developer.atlassian.com/static/javadoc/stash/2.0.1/api/reference/com/atlassian/stash/repository/RepositoryService.html

but I'm not familiar on how I would construct this, public Page<? extends Repository> findByProjectKey (String projectKey, PageRequest pageRequest). Any advice?

BR,

Jennifer

Charles O'Farrell Sep 25, 2013

Hi Jennifer,

Currently our REST resources don't have any notion of 'filtering' or viewing specific fields. It's all or nothing. You will have to grep or parse the results into JSON somehow.

Regarding your second question - how do you mean construct? If you're writing a Java plugin, if you have a component mentioned in atlassian-plugin.xml that can add RepositoryService to your constructor and it will be 'injected' for free. We have a few example plugins here:

http://atlassian.bitbucket.org/#stash

Cheers,

Charles

0 votes
Bill Wang Feb 10, 2015

Here is the way to list all public repositories in STASH project with Linux/Mac boxes,  make sure you have jq installed. 

STASH=&lt;your-stash-server:port&gt;
curl -k -s https://${STASH}/rest/api/1.0/projects/|jq -r ".values[].link.url"|while read line
do
   #echo "curl -k -s https://${STASH}/rest/api/1.0${line}/repos"
   curl -k -s https://${STASH}/rest/api/1.0${line}/repos|jq -r ".values[].cloneUrl"
done
bruce szalwinski Apr 27, 2016

It looks like the /projects request returns the first 25 projects.  If you have more than than, you'll need to paginate through the results or change the size and limit parameters.

.../projects?size=100&amp;limit=100
Prashanth Amarachinta I'm New Here Apr 26, 2019

i am unable to list more than 25 projects , i have more than 25 . how to list them ?

Adam Burden I'm New Here Thursday

should be 

.../projects?size=100&limit=100
0 votes
Jonathan Demeyer Feb 23, 2015

Stashy (Python API client for the Atlassian Stash REST API) works very well !

https://github.com/RisingOak/stashy

 

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,730 views 1 18
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