2

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

Jenkins

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
N. muñoz
  • 115
  • 2
  • 8

2 Answers2

1

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:

  • What is the process, that is trying to connect over SSH?
  • What is the user under which the process is being run?
  • What is the home directory of the user from #2?
  • Is there a SSH Key pair for that user?
  • Is the public key of that key pair trusted with the remote?

The above questions give a framework to think about the problem in a structured way to make progress. Hope this helps someone.

0

Since you are using an SSH URL, make sure:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250