I have a versioned project in Azure devops, which I want to integrate in Jenkins with the Git option that it has.
But Jenkins gives me the following error:
Failed to connect to repository:
Error performing command: git.exe ls-remote -h URL
I have a versioned project in Azure devops, which I want to integrate in Jenkins with the Git option that it has.
But Jenkins gives me the following error:
Failed to connect to repository:
Error performing command: git.exe ls-remote -h URL
Many SO posts indicate that one needs to add the following lines listed in Step 4 to the ~/.ssh/config file, but this solution required knowing more details as to what the ~ should be replaced with for my context of Jenkins. So here are the detailed steps for me to overcome this exact problem. Hope this helps someone.
Step 1: Find out Jenkins Home.
In my case, Jenkins was installed in Ubuntu as a service, and was running under a user(jenkins) without a password. The below code let me run the command to print Jenkins Home directory without logging in as Jenkins
sudo -H -u jenkins bash -c 'echo $HOME'
The directory printed was, /var/lib/jenkins/
Step 2: Generate Key-Pair in the Jenkins Home Directory using the below command.
sudo -H -u jenkins bash -c 'ssh-keygen -t rsa'
This should generate the key pair in the Jenkins Home Directory as listed above.
Your identification has been saved in /var/lib/jenkins/.ssh/id_rsa
Your public key has been saved in /var/lib/jenkins/.ssh/id_rsa.pub
Step 3: Add Public Key Contents to Azure Dev-Ops Repository
This can be done using the following official documentation from Microsoft
[https://learn.microsoft.com/en-us/azure/devops/repos/git/use-ssh-keys-to-authenticate?view=azure-devops][1]
Step 4: If not present, create a file with name config in /var/lib/jenkins/.ssh/ with the following content
Host ssh.dev.azure.com
User git
PubkeyAcceptedAlgorithms +ssh-rsa
HostkeyAlgorithms +ssh-rsa
Step 5: Use the Private Key to configure Credential in Jenkins for connecting to Azure Repo.
This step is important, to establish the trust between public (configured in step 3 in Azure) and private keys (configured in step 5 in Jenkins).
With the above steps, I was able to successfully connect from Jenkins deployed on Ubuntu to Azure Devops. While this was Jenkins+Ubuntu+Azure Devops, the key observations here that can be applied in general to SSH is to understand:
The above questions give a framework to think about the problem in a structured way to make progress. Hope this helps someone.
Since you are using an SSH URL, make sure: