docker - 在 jenkins 上的 docker 中运行 ssh-agent 不起作用
问题描述
我正在尝试在我的 jenkins 管道中使用一个容器,但是我无法让 ssh-agent 在其中工作。我在插件的 v1.19 上,当我运行下面的代码时,我得到
主机密钥验证失败。致命:无法从远程存储库中读取。
请确保您具有正确的访问权限并且存储库存在。
但是,如果我从图像外部运行代码,它可以完美运行,证明用户具有正确的权限。
node('nodeName'){
cleanWs()
ws("short"){
withDockerRegistry([credentialsId: 'token', url: "https://private.repo.com"]) {
docker.image("img:1.0.0").inside("-u root:root --network=host") {
sshagent(credentials: ["bitbucket_token"]) {
sh "mkdir ~/.ssh"
sh 'ssh-keyscan bitbucket.company.com >> ~/.ssh/known_hosts'
sh 'git clone ssh://git@bitbucket.company.com:PORT/repo.git'
}
}
}
}
}
这是输出:
[Pipeline] sshagent
[ssh-agent] Using credentials jenkins (bitbucket_token)
[ssh-agent] Looking for ssh-agent implementation...
[ssh-agent] Exec ssh-agent (binary ssh-agent on a remote machine)
$ docker exec abcdef123456 ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-qwertyu/agent.15
SSH_AGENT_PID=22
Running ssh-add (command line suppressed)
Identity added: /home/jenkins/short@tmp/private_key_8675309.key (/home/jenkins/short@tmp/private_key_8675309.key)
[ssh-agent] Started.
[Pipeline] {
[Pipeline] sh
+ mkdir /root/.ssh
[Pipeline] sh
+ ssh-keyscan bitbucket.company.com
# bitbucket.company.com:22 SSH-2.0-OpenSSH_6.6.1
# bitbucket.company.com:22 SSH-2.0-OpenSSH_6.6.1
# bitbucket.company.com:22 SSH-2.0-OpenSSH_6.6.1
[Pipeline] sh
+ git clone ssh://git@bitbucket.company.com:PORT/repo.git
Cloning into 'repo'...
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
[Pipeline] }
$ docker exec --env ******** --env ******** abcdef123456 ssh-agent -k
unset SSH_AUTH_SOCK;
unset SSH_AGENT_PID;
echo Agent pid 22 killed;
[ssh-agent] Stopped.
[Pipeline] // sshagent
我完全被这个难住了
解决方案
推荐阅读
- python - 如何同时替换多个子字符串
- kubernetes - 在 Kubernetes 上实现区块链
- node.js - 托管节点 ftp 服务器的最简单方法
- ios - AFNetworking 上传数据过长
- docker - Nifi docker 镜像在本地运行,但在 Rancher pod 上找不到敏感的 prop key 错误
- c# - 调用外部函数而不实例化其父类
- raspberry-pi - 使用 VLC 将视频从 Raspberry 流式传输到 PC
- git - 将 master 带回特定的提交
- javascript - 有没有办法在文本区域内有不同颜色的文本?
- postgresql - 如何在 PostgreSQL 中创建特定日期?