1

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 protected]/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?

1 Answer 1

1

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:

3
  • Yep, that's all the issue was. Host key verification needed approving... Thanks!
    – Mcar49
    May 28, 2019 at 14:38
  • Please add more details about host key verification, please. That seemed to be the solution but it's not explained what needs to be done.
    – kutschkem
    Sep 18, 2019 at 11:21
  • @kutschkem on Linux, when you try and connect to something for the very first time, it'll ask you something like "The authenticity of host 10.1.2.3 can't be established. Are you sure you want to continue connecting (yes/no)?" You need to get around this, so once the keys are in place, you can use ssh-keyscan to do it. this is a good example of how to do it.
    – Mcar49
    Oct 1, 2019 at 8:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .