大网数据广告活动
服务器运维问答

Jenkins slave unable to clone from Gitlab

· 52CE 我爱测

I have an autoscaling Jenkins cluster on AWS, which spawns & runs agents via JNLP. Both Master & Slaves run on Ubuntu. I don't quite understand where Jenkins actually stores the SSH keys for Gitlab, or if/how the slaves are expec…

问题原文

原帖链接 · Mcar49 · CC BY-SA 4.0

I have an autoscaling Jenkins cluster on AWS, which spawns & runs agents via JNLP. Both Master & Slaves run on Ubuntu. I don't quite understand where Jenkins actually stores the SSH keys for Gitlab, or if/how the slaves are expected to use it. Whenever I run a Jenkins job on my slaves, I get the following:

git clone [email omitted]/myproject.git 
Cloning into 'build-scripts'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I can confirm the behaviour by SSHing onto the slaves and running the same command manually. The slave .jar is run as a "Jenkins" user, but I'm unable to use a Git clone when being the default "ec2-user", "Jenkins" user, or even as root. I have the Git plugin, Git Credentials plugin, & Git Server plugins installed, which I had previously believed would copy the keys over to the slave on startup. I'm able to run the exact same SSH command from the Master and it works fine, as well as the Master being able to talk to Git to clone repositories as multibranch pipelines.

It might be a simple solution, but I'm a bit stumped. Does anybody know what is required to allow the slaves to SSH/copy the key to somewhere usable?

已采纳解答

原帖链接 · Sukhjinder Singh · CC BY-SA 4.0

My guess is that your ssh key is not added in your github account or Jenkins slave process runs with a different user than the one you used to run git from command line. If that is the case - you'll need to add ssh key to your github accouunt or need to approve the initial host key verification for that user before you can run git in Jenkins. (you know - that message you get when connecting with ssh for the first time:

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。