git 使用 http 身份验证下载私有 BitBucket 存储库 zip 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17682143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:34:09  来源:igfitidea点击:

Download private BitBucket repository zip file using http authentication

githttpbitbucket

提问by user2117190

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

我正在编写一个脚本来轻松部署应用程序。应用程序的代码存储在私有 BitBucket 存储库中。

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

我希望能够下载提交的 zip 文件。我尝试使用以下代码进行身份验证:

https://user:[email protected]/user/repo/get/commit.zip

https://user:[email protected]/user/repo/get/commit.zip

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

但是,它没有完成任务,而是重定向到 BitBucket 上的登录页面。

回答by Nick

Personally, I didn't want to put my password into my script to accomplish this. So the trick was to run the following command, after adding your public key to your bitbucket account:

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

git archive --remote=ssh://[email protected]/your_bitbucket_username/your_repository.git --format=zip --output="name_of_your_desired_zip_file.zip" master

I have multiple keys on my system, if you do too, you will want to create a config file within your ~/.ssh directory that specifies to use a specific key for bitbucket connections.

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

~/.ssh/config

~/.ssh/config

Host bitbucket.org
  StrictHostKeyChecking no
  IdentityFile /home/me/.ssh/my_private_key

回答by GrowlTiger

In order to download a zipped copy of a privateBitbucket repository from the command line, use the following:

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

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

where <username>and <password>are the Bitbucket account name and password, <repository>is the repo name and <branchname>is the branch. If you'd rather download a specific commit, use the SHA-1 hash of the commit in place of <branchname>.

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

The --digestflag is for your security, and is highly recommended.It accomplishes authentication so that your username and password are notsent in the clear. The -oflag sends the output of the curl command to disk as a file, instead of streaming across your terminal screen.

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

Note:Bitbucket's authentication scheme isn't compatible with wget.That is why you must use curl.

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

For publicBitbucket repositories the command is:

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

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

Or alternately, you may use wgetfor public repositories since no authentication is required:

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

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

In addition to .zipformat, you may download repositories in .gzand .bz2flavors. Simply replace .zipin the code above with either .gzor .bz2to download the repository in the compressed format of your choice.

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

回答by Erik van Zijst

The --digest flag is for your security, and is highly recommended. It accomplishes authentication so that your username and password are not sent in the clear.

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

This not true.

这不是真的。

Bitbucket exclusively uses TLS and so at no point does anything go over the wire in clear text. As a result, Digest provides no benefit over Basic Auth. In fact, considering that Digest is server-initiated, you incur an additional server round-trip requesting the server-provided nonce.

Bitbucket 专门使用 TLS,因此在任何时候都不会以明文形式传输任何内容。因此,与基本身份验证相比,摘要没有任何好处。事实上,考虑到 Digest 是服务器启动的,您会产生额外的服务器往返请求服务器提供的随机数。

Our use of Digest has been redundant and deprecated ever since we stopped offering unencrypted HTTP access several years ago and was kept only because there were curl-based scripts doing --digestas suggested by @GrowlTiger.

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

In fact, we are about to turn off Digest altogether on May 1st, after which curl --digestwill cease to work.

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

More info can be found: https://blog.bitbucket.org/2015/04/03/fare-thee-well-digest-access-authentication/

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

回答by laike9m

For those who want to download single file from private repo on bitbucket, I've tried the above but none worked. Finally I got it working with the below command:

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

wget --user=<user> --password=<password> https://bitbucket.org/<user>/<repo>/raw/master/<filename>

回答by mstra001

GrowlTigers answer is great, just an update: with wget it seems to work now, too:

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

wget --user=<username> --password='<password>' https://bitbucket.org/<user>/<repo>/get/<filename>.tar.gz

回答by Joe

Does the tool you're using support basic authentication credentials in the URL? Curl request with digest auth in PHP for download Bitbucket private repositorystrongly implies that:

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

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

works.

作品。

回答by Peter Lenahan

I found that this worked in the newer version of Bitbucket

我发现这在较新版本的 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