Skip to content
Jenkins: Failed to connect to repository

Jenkins: Failed to connect to repository

DodaTech 2 min read

The Jenkins error “Failed to connect to repository” occurs during the SCM checkout stage when Jenkins cannot reach or authenticate with the Git repository. The build fails before any code is fetched.

What It Means

Jenkins attempted to clone or fetch from a Git repository URL configured in the job, but the connection failed. This can happen at the network level (host unreachable), the authentication level (bad credentials), or the protocol level (wrong URL format).

Why It Happens

  • The repository URL is incorrect or missing.
  • SSH keys are not configured in Jenkins credentials for SSH-based repos.
  • Username/password or personal access token is missing or expired for HTTPS repos.
  • The Jenkins agent does not have network access to the Git server.
  • The Git server’s host key has changed or is not trusted.
  • The Jenkins credential ID referenced in the job is wrong or deleted.

How to Fix It

1. Verify the repository URL

git ls-remote https://github.com/user/repo.git

2. Test SSH authentication

ssh -T git@github.com

Expected message: Hi user! You've successfully authenticated...

3. Add credentials in Jenkins

Manage Jenkins → Manage Credentials → Add credential:

  • For HTTPS: Username with password or Personal Access Token
  • For SSH: Private key with passphrase

4. Update the job configuration

In the pipeline or freestyle job, set the correct credential ID under “Git” → “Credentials”.

5. Check Git tool installation

git --version

FAQ

What is a Jenkins credential ID?
A credential ID is a unique string you assign when creating a credential in Jenkins. Pipelines reference it with credentialsId: 'my-id'. If the ID is wrong, Jenkins cannot find the credential.
How do I trust the Git server's SSH host key?
Run ssh-keyscan github.com >> ~/.ssh/known_hosts on the Jenkins agent. You can also disable host key verification in Git settings, though this is not recommended for production.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro