Jenkins returned status code 128 with github
GithubJenkinsGithub Problem Overview
With GitHub command I have:
ssh -T git@github.com
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
Is this problem with public key?
I use Jenkins
under Tomcat 7
/ Ubuntu 12
.
Github Solutions
Solution 1 - Github
This error:
stderr: Permission denied (publickey). fatal: The remote end hung up unexpectedly
indicates that Jenkins is trying to connect to github with the wrong ssh key.
You should:
- Determine the user that jenkins runs as, eg. 'build' or 'jenkins'
- Login on the jenkins host that is trying to do the clone - that is, do not login to the master if a node is actually doing the build.
- Try you ssh to github - if it fails, then you need to add the proper key to
<jenkins user home>/.ssh
Solution 2 - Github
To check are the following:
- if the right public key (id_rsa.pub) is uploaded to the git-server.
- if the right private key (id_rsa) is copied to /var/lib/jenkins/.ssh/
- if the known_hosts file is created inside ~/.ssh folder. Try
ssh -vvv [email protected]
to see debug logs. If thing goes well, github.com will be added to known_hosts. - if the permission of id_rsa is set to 700 (
chmod 700 id_rsa
)
After all checks, try ssh -vvv [email protected]
.
Solution 3 - Github
Also make sure you using the ssh github url and not the https
Solution 4 - Github
In my case I had to add the public key to my repo (at Bitbucket) AND use git clone once via ssh to answer yes to the "known host" question the first time.
Solution 5 - Github
i had sometime ago the same issue. make sure that your ssh key doesn't have password and use not common user account (e.g. better to user account called jenkins or so).
check following article http://fourkitchens.com/blog/2011/09/20/trigger-jenkins-builds-pushing-github
Solution 6 - Github
When I got a similar status code 128
error from Jenkins:
status code 128:
stdout:
stderr: fatal: Couldn't find remote ref refs/heads/jenkins
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2172)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:1864)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:78)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:545)
at jenkins.plugins.git.GitSCMFileSystem$BuilderImpl.build(GitSCMFileSystem.java:358)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:197)
at jenkins.scm.api.SCMFileSystem.of(SCMFileSystem.java:173)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:113)
at org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition.create(CpsScmFlowDefinition.java:67)
at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:299)
at hudson.model.ResourceController.execute(ResourceController.java:97)
at hudson.model.Executor.run(Executor.java:429)
Finished: FAILURE
It was because I hadn't pushed my new branch "jenkins"
that had my Jenkinsfile
. So the solution was to just push my changes
Solution 7 - Github
I deleted my project (root folder) and created it again. It was the fastest and simplest way in my case.
Do not forget to save all you changes, before you delete you project!
Solution 8 - Github
I first had another credential, then when i deleted that, and created a new one, i had the same error. I had to go to every project, and select the new Credential.
Solution 9 - Github
I changed the permission of my .ssh/id_rsa (private key) to 604. chmod 700 id_rsa