Failed to connect to repository : Command "git ls-remote -h - jenkins

I have installed jenkins on my centos7 server and tried to build a maven build. Created a new maven build job and in SCM I was trying to pull the code from github but it showed me an error like...
Failed to connect to repository : Command "git ls-remote -h https://github.com/example.git HEAD" returned status code 128: stdout: stderr: remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/example.git/'
And also I setup an SSH public keys to my github. I don't know how to solve this. Anyone help me.Thanks in advance.

also I setup an SSH public keys to my github
That would have zero impact on an HTTPS URL: the SSH key is ignored.
Check if you havbe a git credential helper in place which might cache your credentials (GitHub username/password)
git config credential.helper
For instance, it could be 'cache'.
I would recommend (as in this answer) to set it to gnome-keyring:
git config --global credential.helper gnome-keyring
Then try again your git ls-remote, from command-line:
git ls-remote https://<yourUsername>#github.com/<yourUsername>/<yourRepo.git>
That should prompt for your GitHub username/password. Once entered, a second git ls-remote should not ask again for your credentials.
From there, an SCM process from your Jenkins, as long as said Jenkins runs with your account, should work.

Related

Failed to connect to repository Error while Building the Maven Jenkins Job

Here is the error I get when trying to configure the SCM URL of the job:
Failed to connect to repository :
Command
"/usr/bin/git ls-remote -h -- https://xgitlab.asee.org/asee-fro/asee-fro.git HEAD"
returned status code 128:
stdout:
stderr: remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://xgitlab.asee.org/asee-fro/asee-fro.git/'
How can I get past this error?
If you have the Jenkins Credentials plugin installed, you should:
register the right account/password required to access xgitlab.asee.org/asee-fro/asee-fro
use that credential in the configuration of your job
Source: Jenkins and GIT Integration using SSH Key (using an SSH creds, but the same process applies for an HTTPS creds)

How to checkout a Bitbucket Git-LFS repo in Jenkins?

I have a Git LFS setup on our Bitbucket server, and can clone it on my Mac since I'm the owner.
Now I'm trying to set this up so a Jenkins job can clone the repo, and so on the SCM section I have
Repository URL: git#server.company.com:user/path/repo.git
Credentials: uernamePwCreds
It can get to the repo fine, but when it tries to checkout a Git-LFS file, it gets the following access error. See the Permission denied (publickey) error on last line.
FATAL: Could not checkout 104e35fb26dc1d3ed1689523cccb6e97829c0feb
hudson.plugins.git.GitException: Command "git checkout -f 104e35fb26dc1d3ed1689523cccb6e97829c0feb" returned status code 128:
stdout:
stderr: Downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (144 KB)
Error downloading object: MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be41): Smudge error: Error downloading MarcomLite/lib/jets3t-0.6.1/cockpit-0.6.1.jar (716be4107b362e413dc1ae29dc88e9b79e680def2c725ecc2d73268c4ea66e75): batch request: Permission denied (publickey).: exit status 255
How do I setup the "Git-LFS-specific" level authentication?
I don't want to use a Jenkinsfile for now.
Try adding "Additional Behaviours" -> "Git LFS pull after checkout" in the Git section of the SCM configuration for your job.

Jenkins and git with custom port

I am trying to link a gitlab instance with a Jenkins instance. Due to being run in a DC/OS environment I cannot use the standard SSH port 22, so I am running gitlab on SSH port 16122 instead.
Gitlab displays SSH clone URLs in the format [git#git.company.de:16122]:user/test.git, which a normal git clone command understands. Also, Jenkins accepts this URI as SCM URI in the configuration screen (as evidenced by the error messages "invalid credentials" vanishing once I set the SSH key as credential that is configured as deploy-key in Gitlab.
The problem arises during actually building the job: jenkins for some unknown reason decides to double-urlencode the [ at the front of the URI and thus the build breaks:
Cloning repository %255bgit#git.company.de:16122]:user/test.git
> git init /var/jenkins_home/workspace/test # timeout=10
Fetching upstream changes from %25255bgit#git.company.de:16122]:user/test.git
> git --version # timeout=10
> git fetch --tags --progress %25255bgit#git.company.de:16122]:user/test.git +refs/heads/*:refs/remotes/origin/*
ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Command "git fetch --tags --progress %25255bgit#git.company.de:16122]:user/test.git +refs/heads/*:refs/remotes/origin/*" returned status code 128:
When I look at the raw XML of the job using xxd on the shell, there are no "invisible" ASCII chars or similar in front of the repo URL.
What causes this, and is there a way to fix this without having to manually rewrite every URL to ssh://git#git.company.de:16122/user/test.git?

Jenkins Failed to Connect to Repository

I am trying to connect Jenkins to a private BitBucket repository.
I have a set (both id_rsa and id_rsa.pub) of SSH keys generated at /var/lib/jenkins/.ssh. I've copied the id_rsa.pub key and pasted it in the deploy keys section of my BitBucket repository. Similarly, running the command git ls-remote -h git#bitbucket.org:user/project.git has a valid return and has been added to known_hosts.
What might be causing my Jenkins to not connect in the git Source Code Management section of Jenkins? The error returned is:
Failed to connect to repository : Command "git -c core.askpass=true ls-remote -h https://git#bitbucket.org/user/project.git HEAD" returned status code 128:
stdout:
stderr: remote: Invalid username or password. If you log in via a third party service you must ensure you have an account password set in your account profile.
fatal: Authentication failed for 'https://git#bitbucket.org/user/project.git/'
I also tried ssh -Tv git#bitbucket.org as per this doc from Atlassian regarding troubleshooting SSH issues. The return states at that:
This deploy key has read access to the following repositories:
user/project: Jenkins -- jenkins#ip-xxx-xx-xx-xxx
For the Project Repository field that Jenkins' Git Plugin provides, it seems that one of their examples shown in their home page for that field (specifically, https://git#bitbucket.org/user/project.git) does not work. It might either be a case of plugin version, or how BitBucket might be configured differently than GitHub, of which their documentation uses for examples.
What did work for me however, was using the git address of the following format:
git#bitbucket.org:user/project.git

Setting git private repository project on jenkins server

I am trying to set git private repo on jenkins server. I have installed git plugin and also github. when I set repo url in jenkins project ui the error is
Failed to connect to repository : Command "git -c core.askpass=true
ls-remote -h git#github.com:repo/project.git HEAD" returned
status code 128:
stdout:
stderr: Permission denied (publickey).
fatal: The remote end hung up unexpectedl
What I have done up to now:
My server user and jenkin user( both are in same server) are different. Though it seems to me these are not related. jenkins user are given all credintial.
In my server under var/lib/jenkins/.ssh(.ssh is created by me) I added ssh key . Public key is added to github repo.
By swithcting user to jenkins i can clone the project by this ssh. So i think there is not any public key adding problem.
I have googled the problem. there are many solutions. I tried most of them. But still no solution. Probably I am missing something.
My repo url is something like this
git#github.com:repo/project.git
If your HOME set in /var/lib/jenkins/ then i hope all the step you have been done successfully :)
Then one thing may be happen for your case. Like when you switch the user by using:
su jenkins
This command means that you switch the user but the home directory will be same as a root's home!
So you need to switch user by confirming the specific user home also switched. TO doing so, you need to follow:
su -s /bin/bash jenkins
Then you need to generate either the ssh public key once again or just update the known host. This will work.
Related Link
It depends on what HOME is set to when Jenkins is running: git will look for the ssh (public and private) keys under $HOME/.ssh.
Simply add a build step with an echo $HOME, and make sure your .ssh is in that folder.

Resources