28

I'm writing a script to easily deploy an application. The code for the application is stored in a private BitBucket repository.

I'd like to be able to download a zip file of the commit. I've tried authenticating with the following code:

https://user:pass@bitbucket.org/user/repo/get/commit.zip

However, instead of accomplishing the task it redirects to the login page on BitBucket.

4

7 回答 7

34

就个人而言,我不想将密码放入我的脚本中来完成此操作。所以诀窍是在将您的公钥添加到您的 bitbucket 帐户后运行以下命令:

git archive --remote=ssh://git@bitbucket.org/your_bitbucket_username/your_repository.git --format=zip --output="name_of_your_desired_zip_file.zip" master

我的系统上有多个密钥,如果您也这样做,您将需要在 ~/.ssh 目录中创建一个配置文件,指定使用特定密钥进行 bitbucket 连接。

~/.ssh/config

Host bitbucket.org
  StrictHostKeyChecking no
  IdentityFile /home/me/.ssh/my_private_key
于 2014-02-18T22:24:21.810 回答
28

要从命令行下载私有Bitbucket 存储库的压缩副本,请使用以下命令:

curl --digest --user <username>:<password> https://bitbucket.org/<username>/<repository>/get/<branchname>.zip -o <branchname>.zip

其中<username><password>是 Bitbucket 帐户名和密码,<repository>是 repo 名称,<branchname>是分支。如果您希望下载特定的提交,请使用提交的 SHA-1 哈希代替<branchname>.

--digest标志是为了您的安全,强烈推荐。它完成了身份验证,因此您的用户名和密码不会以明文形式发送。该-o标志将 curl 命令的输出作为文件发送到磁盘,而不是通过终端屏幕流式传输。

注意: Bitbucket 的身份验证方案不兼容wget.这就是为什么你必须使用curl.

对于公共Bitbucket 存储库,命令是:

curl https://bitbucket.org/<username>/<repository>/get/<branchname>.zip -o <branchname>.zip

或者,您可以使用wget公共存储库,因为不需要身份验证:

wget https://bitbucket.org/<username>/<repository>/get/<branchname>.zip

除了.zip格式之外,您还可以在.gz.bz2风味中下载存储库。只需将.zip上面的代码替换为.gz或者.bz2以您选择的压缩格式下载存储库。

于 2013-07-21T23:46:51.657 回答
11

--digest 标志是为了您的安全,强烈推荐。它完成了身份验证,因此您的用户名和密码不会以明文形式发送。

这不是真的。

Bitbucket 专门使用 TLS,因此在任何时候都不会以明文形式通过网络传输任何内容。因此,Digest 与 Basic Auth 相比没有任何优势。事实上,考虑到 Digest 是服务器启动的,您需要额外的服务器往返请求服务器提供的 nonce。

自从几年前我们停止提供未加密的 HTTP 访问以来,我们对 Digest 的使用一直是多余的,并且被弃用了,只是因为有基于 curl 的脚本--digest按照 @GrowlTiger 的建议进行操作。

事实上,我们即将在 5 月 1 日完全关闭 Digest,之后curl --digest将停止工作。

可以找到更多信息:https ://blog.bitbucket.org/2015/04/03/fare-thee-well-digest-access-authentication/

于 2015-04-03T20:30:55.673 回答
8

对于那些想从 bitbucket 上的私人 repo 下载单个文件的人,我已经尝试了上述方法,但都没有奏效。最后我用下面的命令让它工作:

wget --user=<user> --password=<password> https://bitbucket.org/<user>/<repo>/raw/master/<filename>
于 2015-02-07T12:08:43.940 回答
3

GrowlTigers 的回答很好,只是一个更新:使用 wget 它现在似乎也可以工作了:

wget --user=<username> --password='<password>' https://bitbucket.org/<user>/<repo>/get/<filename>.tar.gz
于 2014-09-05T09:53:48.273 回答
1

您使用的工具是否支持 URL 中的基本身份验证凭据?用于下载 Bitbucket 私有存储库的 PHP 中带有摘要身份验证的 Curl 请求强烈暗示:

curl --user user:pass https://bitbucket.org/user/repo/get/commit.zip >commit.zip

作品。

于 2013-07-17T13:32:00.990 回答
1

我发现这适用于较新版本的 Bitbucket

repository_list=" a b c"
for repository in ${repository_list}
do
    echo "Getting: ${repository}"
    curl --user userid:password \
         http://bitjira.xxx.com:7990/rest/api/latest/projects/WP/repos/${repository}/archive?format=zip  \
         -o ${repository}.zip
done
于 2019-01-15T20:23:04.860 回答