How can I retrieve ALL the ssh urls for the Bitbucket repositories that I have access to, using either a command-line Git command ( CLI ) or using REST call ? I have unsuccessfully
tried to search for the solution for the last week.
Currently, I am in process of moving the source code to bitbucket. Our Atlassian admins are setting up the repositories for our group and we will be using command-line Git commands to add the source code there.
For one of the command line commands - git remote add origin -
I am hoping to avoid having to log-on and access the web interface.
Is it possible? How would I do it? I would prefer command-line, but REST call would also be ok
Thank you
Hello there!
You could achieve that by using one of our Core REST API's:
If you expand the 200 sample response we have on this section of the documentation, you will see that the SSH URL will be on the result:
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"slug": "my-repo",
"id": 1,
"name": "My repo",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PRJ",
"id": 1,
"name": "My Cool Project",
"description": "The description for my cool project.",
"public": true,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://link/to/project"
}
]
}
},
"public": true,
"links": {
"clone": [
{
"href": "ssh://git@<baseURL>/PRJ/my-repo.git",
"name": "ssh"
},
{
"href": "https://<baseURL>/scm/PRJ/my-repo.git",
"name": "http"
}
],
"self": [
{
"href": "http://link/to/repository"
}
]
}
}
],
"start": 0
}
From the REST API above, though, you will need to pass a {projectKey}. You could get the {projectKey} beforehand by using this REST first. Right after that is the sample for a HTTP 200 response:
{
"size": 1,
"limit": 25,
"isLastPage": true,
"values": [
{
"key": "PRJ",
"id": 1,
"name": "My Cool Project",
"description": "The description for my cool project.",
"public": true,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://link/to/project"
}
]
}
}
],
"start": 0
}Programmatically you could retrieve the results of any of the REST endpoints above by using a simple commands like the ones below. Notice that mine is a "bad" example (just because I didn't have SSH keys uploaded to my profile, you can't see the SSH URL):
$ curl -u charlie:charlie http://<BBS_URL>/rest/api/1.0/projects
{
"size":1,
"limit":25,
"isLastPage":true,
"values":[
{
"key":"EH",
"id":1,
"name":"Expert Hour",
"public":false,
"type":"NORMAL",
"links":{
"self":[
{
"href":"http://192.168.123.102/bitbucket/projects/EH"
}
]
}
}
],
"start":0
}
$ curl -u charlie:charlie http://192.168.123.102/bitbucket/rest/api/1.0/projects/EH/repos
{
"size":1,
"limit":25,
"isLastPage":true,
"values":[
{
"slug":"mirror-mirror",
"id":1,
"name":"Mirror Mirror",
"scmId":"git",
"state":"AVAILABLE",
"statusMessage":"Available",
"forkable":true,
"project":{
"key":"EH",
"id":1,
"name":"Expert Hour",
"public":false,
"type":"NORMAL",
"links":{
"self":[
{
"href":"http://192.168.123.102/bitbucket/projects/EH"
}
]
}
},
"public":true,
"links":{
"clone":[
{
"href":"ssh://git@192.168.123.102:7999/eh/mirror-mirror.git",
"name":"ssh"
},
{
"href":"http://charlie@192.168.123.102/bitbucket/scm/eh/mirror-mirror.git",
"name":"http"
}
],
"self":[
{
"href":"http://192.168.123.102/bitbucket/projects/EH/repos/mirror-mirror/browse"
}
]
}
}
],
"start":0
}Let us know if that helps.
Best regards,
Thiago Bomfim
DevTools
1st step you need add Access key ( sshkey ) of the user from which you want clone. Add the ssh key under project-->repository-->settings–>Access Key.
Then execute below command:
git clone ${url}
${url} - SSH protocol ex:- ssh://git@localhost:7999/cit/rlmcqweb.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, thanks. But I have done the adding the sshkey part.
I don't want to clone form the command line. I want to get the ssh url that is for clone and use THAT url with
git remote add origin
I just want to avoid the steps above of having to access the web interface that I mentioned to get the url.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Thiago Bomfim's answer is what you want.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Team,
On the answer above I provided you with the REST endpoint from which you can obtain exactly this information by simply calling curl commands from your client (i.e. no need to use a browser and click through the pages you mentioned).
The response on the JSON above contains the following part which is exactly what you're looking for:
"clone":[
{
"href":"ssh://git@192.168.123.102:7999/eh/mirror-mirror.git",
"name":"ssh"
},
{
"href":"http://charlie@192.168.123.102/bitbucket/scm/eh/mirror-mirror.git",
"name":"http"
}
],I hope that helps.
Thiago
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Thiago.
I am unable to test it for next two weeks, but this is exactly what I am looking for.
I will post a comment, if I run into any issues when I test.
Thanks again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not a problem.
All the best with your test.
Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, this may seem to be a very basic question, but we just started using Atlassian suite and everyone including the admins are learning as we go. Do the admins need to set-up something to allow us to use the REST APIs?
Our Bitbucket version is 4.6.2.
When I tried both https://git-dev.company.com/bitbucket/rest/api/1.0/ OR
https://git-dev.company.com/bitbucket/rest/api/2.0/
I get a 404
The repositories are definitely defined at https://git-dev.company.com/repos?visibility=public as I see a list of test repositories at above url
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi team,
If you type on your browser:
https://git-dev.company.com/bitbucket/rest/api/1.0/projects
That should enable you to get results.
The best way though is by using curl as I indicated above.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for a quick response.
I will be using curl for getting the information. I just tried with curl but didn't get the result, so I thought I will just verify the url and that is why I typed it in browser to verify my url is not invalid. I tried with https://git-dev.company.com/bitbucket/rest/api/1.0/projects, but still get a 404. That is why I am wondering, if the admins need to do anything before I can use the REST calls for any of the Atlassian suite products - I am starting with BitBucket, but once I get a handle on it, I will try to automate my work using REST calls for the others - Bamboo, Confluence and JIRA
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.