git Jenkins 通过 SSH 访问私有 BitBucket 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18869045/
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:59:58  来源:igfitidea点击:

Jenkins access private BitBucket repo over SSH

gitsshjenkinsbitbucket

提问by user2424511

I'm having trouble getting Jenkins to clone a git repository on BitBucket via SSH. It's failing with the following message:

我无法让 Jenkins 通过 SSH 在 BitBucket 上克隆 git 存储库。它失败并显示以下消息:

Building in workspace /var/lib/jenkins/workspace/test
[ssh-agent] Using credentials git ([email protected]:<user>/<repo>.git)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent]   Java/JNR ssh-agent
[ssh-agent] Started.
Checkout:test / /var/lib/jenkins/workspace/test - hudson.remoting.LocalChannel@2b619bca
Using strategy: Default
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
ERROR: Problem fetching from origin / origin - could be unavailable. Continuing anyway
hudson.plugins.git.GitException: Command "git fetch -t origin +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: ssh: connect to host bitbucket.org port 22: Connection refused
fatal: The remote end hung up unexpectedly

Steps taken

采取的步骤

  • Create an SSH keypair
  • Add the public key as a deployment key for the repository on BitBucket
  • Install the SSH key and username (have tried both 'git' and my BB account name) in the Jenkins Credentials manager plugin
  • Attempt to clone the repository in the build using a URL in form of

    [email protected]:<user>/<repo>.git

  • 创建 SSH 密钥对
  • 将公钥添加为 BitBucket 上存储库的部署密钥
  • 在 Jenkins Credentials manager 插件中安装 SSH 密钥和用户名(已经尝试了 'git' 和我的 BB 帐户名)
  • 尝试使用 URL 形式克隆构建中的存储库

    [email protected]:<user>/<repo>.git

I've also tried not using the credentials manager and manually installing the keys in /var/log/jenkins/.ssh/, but to no avail.

我也试过不使用凭证管理器并在 中手动安装密钥/var/log/jenkins/.ssh/,但无济于事。

Any ideas what I'm doing wrong?

任何想法我做错了什么?

采纳答案by user2424511

As @user1562655 suggested out, the clone was failing due to another issue -- in this case the firewall was blocking outgoing ssh on port 22.

正如@user1562655 所建议的那样,克隆由于另一个问题而失败——在这种情况下,防火墙阻止了端口 22 上的传出 ssh。

The fix was to use port 443 (as the server allows this), and a different BitBucket URL:

修复方法是使用端口 443(因为服务器允许这样做)和不同的 BitBucket URL:

ssh://[email protected]:443/<user>/<repo>.git

…instead of

…代替

ssh://[email protected]:<user>/<repo>.git

More info on the scheme is available here:

有关该计划的更多信息,请访问:

UsetheSSHprotocolwithBitbucket-SSHonPort443

使用 SSH 协议和 Bitbucket-SSHonPort443