Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
2 views
in DevOps and Agile by (29.3k points)

with github command I have

ssh -T [email protected]

Hi (MyName)! You've successfully authenticated, but GitHub does not provide shell access.

my connection with github is ok no problem, but with jenkins, I have this error

ERROR: Error cloning remote repo 'origin' : Could not clone [email protected]:Name-MysRepo/MyRepo.git

hudson.plugins.git.GitException: Could not clone [email protected]:Name-MysRepo/MyRepo.git

    at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.clone(CliGitAPIImpl.java:219)

    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1001)

    at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:942)

    at hudson.FilePath.act(FilePath.java:904)

    at hudson.FilePath.act(FilePath.java:877)

    at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:942)

    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1101)

    at hudson.model.AbstractProject.checkout(AbstractProject.java:1369)

    at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:676)

    at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)

    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:581)

    at hudson.model.Run.execute(Run.java:1575)

    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:477)

    at hudson.model.ResourceController.execute(ResourceController.java:88)

    at hudson.model.Executor.run(Executor.java:241)

Caused by: hudson.plugins.git.GitException: Command "git clone --progress -o origin [email protected]:Name-MysRepo/MyRepo.git /root/.jenkins/jobs/TestKRGDAOV01/workspace" returned status code 128:

stdout: Cloning into '/root/.jenkins/jobs/TestKRGDAOV01/workspace'...

stderr: Permission denied (publickey).

fatal: The remote end hung up unexpectedly

why this problem with publickey I use Jenkins under TomCat7 / ubuntu 12 help me in this issue. 

2 Answers

0 votes
by (50.2k points)

The error that shows in this question indicates that Jenkins is trying to connect git-hub with the wrong ssh key.

To resolve this particular error you need to use:

 Determine the Jenkins user which runs as 'build' or 'Jenkins'

Log on to the Host machine of Jenkins and try to do clone but not on the Jenkins host.

Try to ssh now, If it fails again then you need to add a proper key to /.ssh.

0 votes
ago by (1.2k points)

This most probably means Jenkins under Tomcat cannot make use of the SSH keys used in your GitHub account. This is how to resolve the problem and how it could be debugged: check if the SSH key utilized for accessing the GitHub environment has been saved under Jenkins's home directory which will depend on whether you install Jenkins under its user and typically will be located either under /root/.ssh or /var/lib/jenkins/.ssh.

Copy or Create New Key For Jenkins:

You should not have a problem if one does not yet exist - copy your key over here, or make a new one from under Jenkins here using:

Code : 

sudo -u jenkins ssh-keygen -t rsa -b 4096 -C "[email protected]"

Add the key contents that are in the.pub file into GitHub under: Settings > SSH and GPG keys

Test connectivity of Jenkins towards GitHub by clicking on "Add New SSH Key….

Run bash with Jenkins and verify connection. 

Code :

sudo -u jenkins ssh -T [email protected]

You should see a response it is really nice and it should be able.

Change Jenkins settings for Git Plugin, (if you changed)

Step1:

Login to Jenkins >> Jenkins Configuration >> System Configuration >> Git plugin

This should read like the SSH key choice you made and put it in the proper placement to the path of that new SSH key you made above.

That should then cause Jenkins to authenticate with SSH on GitHub and eliminate the Permission denied (publickey) error.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...