This is still a huge problem for me and is stopping me from being able to update to the latest version of Jenkins. I took some time and spun up a fresh install of jenkins to do some testing.
Jenkins 2.375.3
Credentials plugin [1214.v1de940103927]
When I ssh into the fresh jenkins install and run:
sudo su - jenkins -s /bin/bash
whoami
jenkins
I can confirm that I am the jenkins user. I am able to run: git ls-remote ssh://git@repo-url/path/reponame/repo.git
successfully and see all the different branches that exist in my code repo.
I am using ssh connection to connect to our git repo and can confirm permissions and files are in place:
ls -al /var/lib/jenkins/.ssh/
total 24
drwxrwxr-x. 2 jenkins jenkins 53 Mar 7 17:04 .
drwxr-xr-x. 16 jenkins jenkins 8192 Mar 7 17:42 ..
-rw-------. 1 jenkins jenkins 235 Mar 7 17:03 config
-r--------. 1 jenkins jenkins 1675 Mar 7 17:03 id_rsa
-rw-r--r--. 1 jenkins jenkins 399 Mar 7 17:04 known_hosts
At this point I am able to confirm that as the jenkins user… I can access the repository successfully.
Once I create a freestyle project and add ssh://git@repo-url/path/reponame/repo.git
to the source code management repository URL I immediately get the same status code 128 error. I created global credentials using “SSH Username with private key” where I inputed the git username with the private key that I can confirm is working via terminal.
Here is full output of job failure:
Started by user My Name
Running as SYSTEM
Building in workspace /var/lib/jenkins/workspace/ssh-connection
The recommended git tool is: NONE
using credential f13366cf-10bb-42ca-9548-806da50ebd0d
> /bin/git rev-parse --resolve-git-dir /var/lib/jenkins/workspace/ssh-connection/.git # timeout=10
Fetching changes from the remote Git repository
> /bin/git config remote.origin.url ssh://git@repo-url/path/reponame/repo.git # timeout=10
Fetching upstream changes from ssh://git@repo-url/path/reponame/repo.git
> /bin/git --version # timeout=10
> git --version # 'git version 2.39.2'
using GIT_SSH to set credentials
Verifying host key using known hosts file
> /bin/git fetch --tags --force --progress -- ssh://git@repo-url/path/reponame/repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
ERROR: Error fetching remote repo 'origin'
hudson.plugins.git.GitException: Failed to fetch from ssh://git@repo-url/path/reponame/repo.git
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1003)
at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1245)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1309)
at hudson.scm.SCM.checkout(SCM.java:540)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1241)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:649)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:85)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:521)
at hudson.model.Run.execute(Run.java:1900)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:44)
at hudson.model.ResourceController.execute(ResourceController.java:107)
at hudson.model.Executor.run(Executor.java:449)
Caused by: hudson.plugins.git.GitException: Command "/bin/git fetch --tags --force --progress -- ssh://git@repo-url/path/reponame/repo.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
stdout:
stderr: 17:35:44.812309 git.c:460 trace: built-in: git fetch --tags --force --progress -- ssh://git@repo-url/path/reponame/repo.git '+refs/heads/*:refs/remotes/origin/*'
17:35:44.812533 read-cache.c:2481 performance: 0.000006996 s: read cache .git/index
17:35:44.812718 run-command.c:655 trace: run_command: unset GIT_PREFIX; GIT_PROTOCOL=version=2 '"ssh -vvv"' -o SendEnv=GIT_PROTOCOL git@repo-url 'git-upload-pack '\''/path/reponame/repo.git'\'''
"ssh -vvv": ssh -vvv: command not found
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
17:35:44.814756 trace.c:411 performance: 0.002698970 s: git command: /bin/git fetch --tags --force --progress -- ssh://git@repo-url/path/reponame/repo.git'+refs/heads/*:refs/remotes/origin/*'
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2734)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandWithCredentials(CliGitAPIImpl.java:2111)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$1.execute(CliGitAPIImpl.java:623)
at hudson.plugins.git.GitSCM.fetchFrom(GitSCM.java:1001)
... 11 more
ERROR: Error fetching remote repo 'origin'
Finished: FAILURE
I have confirmed that my private key and public key connection is working and correct.
For whatever reason I am still unable to get a jenkins job on the controller to successfully connect to my git repo after updating… or in this specific case… I cant even set it up on a fresh install as it seems jenkins jobs are unable to access my credentials properly.
Any continued support would be greatly appreciated… this problem is forcing me to consider different tools such as Github for our CI/CD pipelines.