10

I am trying to clone a bitbucket server repo (self-hosted) using access-token however I could not find any documentation on Bitbucket server API. My clone url is ssh based.

Or is there a way to use REST API curl command to clone bitbucket server repos?

Kaushal Kapoor
  • 442
  • 1
  • 5
  • 14
  • 1
    Where are you trying to clone your repo: your local machine? You don't use the Bitbucket API for that, just `git clone `... – msanford Jun 25 '19 at 18:57
  • Thanks for you reply. I need to automate that part so I have to add the authentication details for validation in the script. – Kaushal Kapoor Jun 25 '19 at 18:59
  • 1
    Probably the simplest solution is to use an [ssh key](https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html) for that, not a PAT you'd use for the API. – msanford Jun 25 '19 at 19:00
  • @msanford Is there a way/syntax to automate the validation using ssh keys then? – Kaushal Kapoor Jun 26 '19 at 07:20
  • What validation do you want to do exactly? (Can you [edit](https://stackoverflow.com/posts/56760396/edit) the question and add that?) – msanford Jun 26 '19 at 13:52
  • Using a ssh key is simple, but your ssh key typically has write access (unless you create a separate account) whereas your access token can be restricted to reading. – Helmut Grohne Dec 02 '19 at 10:19

3 Answers3

19

The official documentation says that you should:

git clone https://x-token-auth:$ACCESS_TOKEN@yourbitbucketserver/...

In my experiments with a BitBucket 6.1 server, this does not work and gives HTTP 401 instead. Using ssh with access tokens seems to be entirely unsupported.

What did work was:

git -c "http.extraHeader=Authorization: Bearer $ACCESS_TOKEN" clone https://yourbitbucketserver/...
Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
Helmut Grohne
  • 6,578
  • 2
  • 31
  • 67
0

To clone over SSH you'll want to use an SSH key, note you can add more than one SSH key to a user account in Bitbucket Server, so you can identify with a specific SSH key if you'd like.

If you like the extra permission control that the Personal Access Tokens give you, you can clone over HTTPS, as our PATs are designed specifically for clone over HTTPS, and authenticating to the REST API using Basic Auth / Bearer token.

For more information see https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html

JVDL
  • 1,157
  • 9
  • 16
0
git clone -c http.extraHeader='Authorization: Bearer BBDC-xxxxxx' https://bitbucket.example.com/scm/~myusername/my_repo.git

Per https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html

marsteel
  • 1
  • 1