如何在Jenkins上创建Protractor任务?Git仓库连接失败排查
Hey there! Let's tackle this Git connection issue you're facing in Jenkins on Ubuntu 16.04. That git ls-remote error usually points to a few common problems—here are the fixes I've seen work most often:
Jenkins needs Git to be present on the underlying Ubuntu machine. Run this command on your server terminal to verify:
git --version
If it's not installed, get it set up with:
sudo apt-get update && sudo apt-get install git
After installing, restart Jenkins to make sure it picks up the new tool:
sudo systemctl restart jenkins
Sometimes Jenkins doesn't automatically detect the Git executable path. Head to Manage Jenkins > Global Tool Configuration, find the Git section, and double-check the "Path to Git executable" field. On Ubuntu 16.04, this is almost always /usr/bin/git—you can confirm the exact path with:
which git
Save the configuration and try connecting your repository again.
If you're using an HTTPS URL for your GitHub repo:
- For public repos: First make sure your server can reach GitHub at all. Test connectivity from the terminal:
If this fails, check your server's firewall rules or proxy settings—something might be blocking the connection.curl https://github.com - For private repos: You'll need to add valid credentials in Jenkins. When pasting your repo URL, click the Add button next to "Credentials", select "Username with password", enter your GitHub username and a personal access token (PAT) (GitHub no longer supports account passwords for Git operations), then pick those credentials from the dropdown.
If your Ubuntu server is behind a proxy, Jenkins might not be set up to use it. First, go to Manage Jenkins > Manage Plugins and ensure the Proxy Configuration plugin is installed. Then navigate to Manage Jenkins > Configure System, scroll to the Proxy section, enter your proxy details, and use the "Test proxy" button to verify it can reach GitHub.
The jenkins user needs permission to run Git commands and access network resources. You can test this by switching to the jenkins user and running the problematic command directly:
sudo su - jenkins git ls-remote -h https://github.com/your-username/your-repo.git
If this fails, fix any permission issues—for example, if you're using SSH keys instead of HTTPS, make sure the jenkins user has access to the correct key pair.
After trying these steps, go back to your Jenkins project configuration and test the Git repository connection again. Most of the time, one of these fixes will resolve that git ls-remote error.
内容的提问来源于stack exchange,提问作者Rahul Solanki

