【发布时间】:2021-05-28 14:44:36
【问题描述】:
我无法让 Jenkins 通过 SSH 在 BitBucket 上克隆一个 git 存储库。失败并显示以下消息:
Building in workspace /var/lib/jenkins/workspace/test
[ssh-agent] Using credentials git (git@bitbucket.org:<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
采取的步骤
- 创建 SSH 密钥对
- 将公钥添加为 BitBucket 上存储库的部署密钥
- 在 Jenkins 凭据管理器插件中安装 SSH 密钥和用户名(已尝试过“git”和我的 BB 帐户名)
-
尝试使用
形式的 URL 克隆构建中的存储库git@bitbucket.org:<user>/<repo>.git
我也尝试过不使用凭据管理器并在/var/log/jenkins/.ssh/ 中手动安装密钥,但无济于事。
任何想法我做错了什么?
【问题讨论】:
-
克隆是否从命令行工作? Jenkins 可能以用户“jenkins”的身份运行,这可能与您尝试克隆的用户不同... Jenkins 必须以您为其上传密钥的用户“用户”运行...
-
实际上,不 - 原来是防火墙问题。感谢您的帮助。
-
FWIW 将密钥从我的用户帐户复制到
/var/lib/jenkins/.ssh帮助我解决了类似问题