如何设置GoCD来处理使用SSH密钥进行身份验证的私有git存储库?

ksz*_*tan 8 git ssh continuous-integration go-cd

我有一个git存储库,用SSH密钥对用户进行身份验证,我想将该repo用作GoCD资料.GoCD给了我这个错误:

Error performing command: --- Command ---
git ls-remote ssh://git@server/repo.git refs/heads/master
--- Environment ---
{GIT_ALLOW_PROTOCOL=http:https:ssh:git:file:rsync}
--- INPUT ----

--OUTPUT ---

--- ERROR ---
STDERR: Host key verification failed.
STDERR: fatal: Could not read from remote repository.
STDERR: 
STDERR: Please make sure you have the correct access rights
STDERR: and the repository exists.
---
Run Code Online (Sandbox Code Playgroud)

有什么方法可以将SSH密钥添加到GoCD吗?

ksz*_*tan 12

在撰写此答案时,无法直接在GoCD中管理SSH密钥.要使其工作,您必须为GoCD服务器和所有代理生成SSH密钥,然后将它们添加到托管git存储库的服务器.您也可以将现有密钥复制到服务器和节点,但显然不建议这样做.

例如,对于标准的GoCD服务器安装,您的系统中应该有"go"用户:

$ grep GoCD /etc/passwd
go:x:998:998:GoCD User:/var/go:/bin/bash
Run Code Online (Sandbox Code Playgroud)

sudo作为"go"用户并创建密钥

$ sudo su - go
$ ssh-keygen
...
$ ssh [server]
The authenticity of host '[server] ([1.3.3.7])' can't be established.
ECDSA key fingerprint is SHA256:Rxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[server]' (ECDSA) to the list of known hosts.
Permission denied (publickey,keyboard-interactive).
Run Code Online (Sandbox Code Playgroud)

最后一步很重要,因为如果你不这样做,GoCD会给你同样的错误.

现在将您的密钥添加到git服务器,然后单击GoCD中的"检查连接".它应该打印"连接正常".

为每个节点和运行代理的用户生成密钥.