Jenkins输入仓库URL时提示‘Failed to connect to repository’故障求助
Based on your description — this issue popping up after 100 successful builds, working fine on another machine with the same config — the problem is almost certainly tied to the local machine's environment rather than your Jenkins/Git setup itself. Let's walk through targeted fixes:
1. Clear Git's Local Credential Cache
Windows often caches old Git credentials that override Jenkins' configured ones. Here's how to reset it:
- Open Credential Manager (search in Windows Start menu), go to Windows Credentials, and delete any entries linked to
github.com. - Alternatively, run this Git command to disable credential caching temporarily:
Trigger a Jenkins build afterward — if it prompts for credentials, use the valid PAT/username+password you know works.git config --global --unset credential.helper
2. Validate Jenkins Credential Configuration
Double-check even if you think it's correct:
- Ensure you're using the Username with password credential type. If using a GitHub Personal Access Token (PAT), you can enter any dummy username and the PAT as the password (this is a common gotcha).
- Verify the credential ID selected in your Jenkins job matches exactly what you created in Jenkins' Credentials store — typos here are easy to miss.
- Test manually on the machine: Open Command Prompt, run:
Enter your valid credentials. If this fails, the issue is with Git/network on the machine; if it works, Jenkins isn't pulling the credentials correctly.git ls-remote -h https://github.com/org/project.git HEAD
3. Check Git Proxy & Version Settings
- Proxy settings can break suddenly. Run these commands to check and clear proxy config:
git config --global --get http.proxy git config --global --get https.proxy git config --global --unset http.proxy git config --global --unset https.proxy - Compare the Git version on this machine to the working one. Outdated Git versions can have compatibility issues with GitHub's API — upgrade to the latest stable version if there's a mismatch.
4. Verify Jenkins Service Permissions
Jenkins runs as a Windows service, and the account it uses might lack network or credential access:
- Open Services (search in Start), find the Jenkins service, right-click > Properties.
- Go to the Log On tab, select This account, and enter the local admin account you used to test Git manually.
- Restart the Jenkins service and re-run the build.
5. Rule Out Firewall/Security Software Interference
Firewalls or antivirus tools often block Git/Jenkins network requests unexpectedly:
- Temporarily disable your firewall and any antivirus software, then test the build.
- If it works, add exceptions for
git.exe(located atC:\Program Files\Git\bin\git.exe) and Jenkins' Java process to your security tools.
6. Check GitHub Access Restrictions
- Confirm the machine's public IP isn't blocked by GitHub (e.g., from too many previous requests). Open a browser on the machine and try accessing the repository URL directly — if you can't reach it, you may need to check network routing or contact your IT team.
Since the same config works on another machine, focusing on local machine-specific factors (credentials, permissions, network blocks) will resolve this issue.
内容的提问来源于stack exchange,提问作者Shiva555

