Unable to clone repository to jenkins on linux - linux

I am able to clone a repository that i've created for one of my jobs on jenkins. Whereas, cloning a repository which is a fork of another repository gives the following error when trying to build it - Any suggestions on what could be the problem?
Started by user anonymous
Building in workspace /var/lib/jenkins/jobs/client1/workspace
Checkout:workspace / /var/lib/jenkins/jobs/client1/workspace - hudson.remoting.LocalChannel#1d5cac4
Using strategy: Default
Cloning the remote Git repository
Cloning repository https://..... (couldn't disclose the address link here)
git --version
git version 1.7.9.5
ERROR: Error cloning remote repo 'origin' : Could not clone https://.....
hudson.plugins.git.GitException: Could not clone https://......
at hudson.plugins.git.GitAPI.clone(GitAPI.java:273)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:1044)
at hudson.plugins.git.GitSCM$2.invoke(GitSCM.java:986)
at hudson.FilePath.act(FilePath.java:865)
at hudson.FilePath.act(FilePath.java:838)
at hudson.plugins.git.GitSCM.determineRevisionToBuild(GitSCM.java:986)
at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1142)
at hudson.model.AbstractProject.checkout(AbstractProject.java:1331)
at hudson.model.AbstractBuild$AbstractBuildExecution.defaultCheckout(AbstractBuild.java:682)
at jenkins.scm.SCMCheckoutStrategy.checkout(SCMCheckoutStrategy.java:88)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:587)
at hudson.model.Run.execute(Run.java:1557)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:236)

My first guess would be that the user jenkins is running as does not have permission to access the git repo.
I would try logging into the server and running
sudo su <jenkins_user_name>
git clone https://.....
You may just need to add the server to your known hosts if the SSH Keys are already setup.

Related

git clone from internal gitlab repository doesn't work unless I'm running as root

I'm trying to clone an internal gitlab repository, but it keeps giving me this error message
fatal: unable to access 'https://gitlab**************.git/': gnutls_handshake() failed: Error in the pull function.
But somehow, if I'm running as root, the cloning process would run perfectly.
The problem is, I needed this to work because I'm trying to use this repository on Jenkins.
Can someone help me or explain why it only worked if I'm running as root?
root uses the same version of git and curl.
But it does not use the same:
global git config: compare the output of git config --global -l in both instances (root and regular user account).
environment configuration (type env in both cases, and compare the environment variables)
In particular, look for sslcainfo (git config --global -l|grep -i ssl) which could reference the certificate needed to contact through TLS your on-premise HTTPS GitLab URL.

Jenkins job fails with git "git clone" using ssh key

I am trying to run python test cases through Jenkins, it has the git clone command with ssh key.
Command : git clone -v ssh://user#host:29418/project folder_to_clone
Getting the error like :
Warning: Permanently added '[host]:29418,[100.64.42.4]:29418' (RSA) to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
But while running locally everything fine, On Jenkins only getting this issue.
You need to add create a shh key using ssh-key , add it to both jenkins credentials and the git repository you are trying to fetch the code from.

Git pull via SSH

I try set up jenkins for automatically execute git pull from bitbucket. I created an SSH on repository and executed ssh -T git#bitbucket.org and got response:
authenticated via a deploy key. You can use git or hg to connect to Bitbucket. Shell access is disabled.This deploy key has read access to the following repositories:
If I try execute ssh git pull the console does infinite loading.. Why?
Did you clone repository? You should be able to login to Bitbucket web interface and in you profile add your public SSH key.
Then you can clone repository. From Bitbucket webinterface --> repo --> click on clone. This will pop up window with ssh command to clone repository.
Once you repo is cloned, you should be able to use
git pull
...edit,add,commit
git push
There is no need to manually open SSH connection - git will do it itself. You just need to tell git to pull a specify from which repository. Git will parse the URL, and invoke SSH if needed.
And this is the best practice to disable shell access to git hosts. See e.g. https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server

Gitlab: While cloning a repo via ssh it keeps asking for password

I have installed gitlab on LINUX(RHEL 6.7). While cloning the repo via ssh it keeps asking for the password for git, however it is working fine by using http:
$ git clone http://MGJV67#il06epclin1.am.mot-solutions.com/MGJV67/NewPROJ.git
Cloning into 'NewPROJ'...
warning: You appear to have cloned an empty repository.
mgjv67#mgjv67-430 MINGW64 /c/TCS/Gitlab/NewPROJ (master)
$ git clone git#il06epclin1.am.mot-solutions.com:MGJV67/NewPROJ.git
Cloning into 'NewPROJ'...
git#il06epclin1.am.mot-solutions.com's password:
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
While you can clone anonymously over http, you can only clone over SSH with a valid SSH identity.
Create an SSH key and add the public key to your Gitlab user account, or add it as a deploy key for your project in case you only need read-only access.

CentOS: Git: "fatal: could not read from the remote repository"

( I have already read through this, and several other posts, thoroughly git: fatal: Could not read from remote repository )
I'm using my own server as a git server. I set it up according to several guides. Everything is fine except any operation that read or writes to the remote git repository.
Problem:
When I try to do anything that interacts with the remote server that I have set up, I get:
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository
exists.
in windows shell. In Cygwin it just hangs.
Quick Background:
I'm using CentOS 7 as the server and Windows 10 as the client.
On the server:
I made a new user 'git'
mkdir /home/git/myproject.git
git init --bare
opened up necessary ports 9418, 22, & 443 using:
"firewall-cmd --permanent --add-port=22/tcp" and
"firewall-cmd --reload"
On the client:
created a folder, created a text file with some text, ran 'git init', 'git add .'
setup rsa keys according to several guides
What Works:
I can ssh into the server fine with windows shell, cygwin and puTTy. The folder /home/git/mproject.git exists. git has been working fine locally using either windows shell or Cygwin.
Attempted solutions:
I've tried:
chmod 600 pyproject.git
chmod 700 pyproject.git
chmod 777 pyproject.git
git remote add origin git#my-site.com:/home/git/myproject.git
git remote add origin git#my-site:/home/git/myproject.git
git remote add origin ssh://git#my-site.com/home/git/myproject.git
git remote add origin ssh://git#my-site.com/repo-<wbr< a="">>/home/git/myproject.git..git
git remote add origin ssh://git#my-site.com/repo-<wbr< a="">>/home/git/myproject.git
git remote add origin git#my-site.com:/home/git/myproject.git
git clone git#my-site.com:/home/git/myproject.git
git remote add origin https://git#my-site.com/home/git/myproject.git
git clone ssh://git#my-site.com/home/git/myproject.git
git clone ssh://git#my-site.com/myproject.git
git clone https://git#my-site.com:myproject.git
git clone ssh://git#my-site.com/home/git/myproject.git
git clone git#my-site.com/home/git/myproject.git
git clone git#my-site.com:/home/git/myproject.git
git clone git#my-site.com/myproject.git
I can log into the server with ssh git#my-site.com just fine. I can also navigate to the /home/git/myproject.git folder. The ports are open. What else could be wrong?
So the problem seems to have been that the client and the server were using versions of git that were very different. The client was using 1.9 I believe, and the server was using 2.6. Not only that, the versions of git differed depending on the whether I was using windows terminal or Cygwin.
Now, after removing old versions and updating git, commands like:
git remote add origin git#mysite.com:/home/git/myproject.git
git push origin master
work correctly.

Resources