Home > Blockchain >  Git SSH checkout fails with Jenkins and GitLab
Git SSH checkout fails with Jenkins and GitLab

Time:10-21

When I attempt a build on my Jenkins job that is configured to checkout from GitLab I am getting below error output (truncated) :

    ....................
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from [email protected]:root/xxx.git
    at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
    at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1242)
    at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1302)
    ....................................................
        ....................................................
    at hudson.model.Executor.run(Executor.java:431)
Caused by: hudson.plugins.git.GitException: Command "git fetch --tags --force --progress -- [email protected]:root/xxx.git  refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout: 
stderr: Load key "/var/lib/jenkins/workspace/gitlabjenkinsdemo@tmp/jenkins-gitclient-ssh1964800292912998995.key": invalid format
Permission denied, please try again.
Permission denied, please try again.
[email protected]: Permission denied (publickey,password).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2681)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2102)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.access$500(CliGitAPIImpl.java:86)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:624)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:999)
... 11 more

ERROR: Error fetching remote repo 'origin' Finished: FAILURE

I am trying to setup a CI/CD pipeline as per this post GITLABERROR

What am I missing ?

CodePudding user response:

Both Jenkins server and Gitlab server are running on the same Debian instance

Ideally, they would run with their own associated service account, not "root".

But still, even as root, this should work.
Check which private SSH key you have added, and make sure, at least for testing, it wasn't one protected with a passphrase (meaning the private key file does not have a Proc-Type: 4,ENCRYPTED line in it)

That might be a cause for the jenkins-gitclient-ssh1964800292912998995.key": invalid format you have.
(That or you have copied the private key file content with CRLF instead of LF as end-of-line)
(or you have copied a public key, where a private one was expected, or vice-versa)

From the discussion:

  • the private key had to be registered again in Jenkins (making sure its eol -- end-of-line -- are LF, not CRLF)
  • the branch needs to be renamed:

My repo had master when I did git init, so had to rename branch to main when I set the GitLab remote

  • Related