Can't clone from bitbucket repository - amazon-ec2

I can't clone git repository from BitBucket by jenkins on amazon ec2.
OS:Centos
Git:2.0.4
Step which done:
Add ssh key to bitbucket
Add bitbucket to known_host
jenkins run from user tomcat
directory listing:
drwx------ 2 tomcat tomcat 4096 Nov 14 15:51 .
drwx------ 3 tomcat tomcat 4096 Nov 14 08:40 ..
-rw------- 1 tomcat tomcat 1675 Nov 14 08:41 id_rsa
-rw-r--r-- 1 tomcat tomcat 404 Nov 14 08:41 id_rsa.pub
-rw-r--r-- 1 tomcat tomcat 806 Nov 14 08:55 known_host
Here ps -ef | grep jenkins
tomcat 1544 1 0 Nov14 ? 00:03:46 /etc/alternatives/java Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8090 --ajp13Port=8019 --debug=5 --><handlerCountMax=100 --handlerCountMaxIdle=20
tomcat 7018 6957 0 17:04 pts/0 00:00:00 grep jenkins
In jenkins configuration job I see
Failed to connect to repository : Error performing command: git ls-remote -h git#bitbucket.org:my-account/my-repo.git HEAD
When I run job to build I got error
Cloning the remote Git repository
Cloning repository git#bitbucket.org:my-account/my-repo.git
> git init /var/lib/jenkins/workspace/Build-project # timeout=10
ERROR: Error cloning remote repo 'origin'
ERROR: Error cloning remote repo 'origin'
Finished: FAILURE
When I tried to clone directly from command line everything works fine
Could you please help me to solve a problem.

Are you specifying your repository credentials correctly? In the Source Code Management section of the job configuration, click the Add button to add a Credentials entry that uses the SSH key you added to your Bitbucket repo. I usually save my private key file on the filesystem where it's readable only by Tomcat, select the "From a file on Jenkins master" option in the Add Credentials dialog, and specify the path to my private key file. Make sure the Username is git (as in git#bitbucket.org).
Once you've added the credentials, select that entry from the dropdown list in the job configuration. When the focus leaves that box, an error message will appear if Jenkins is unable to git ls-remote from that repo using the credentials you provided.

Related

How to initialize git without the global directory?

I want to put my LARAVEL project from the git repository to my server, to do this I:
git init
sudo git clone git#gitlab.com:test-name/my-project.git
Now I have the following content:
drwxr-sr-x 4 ubuntu www-data 37 Mar 26 08:53 ./
drwxr-xr-x 6 root root 101 Sep 5 2019 ../
drwxr-sr-x 7 root www-data 119 Mar 26 08:53 .git/
drwxr-sr-x 12 root www-data 4096 Mar 26 08:53 my-project/
and now when I list my-project I also see .git\ directory !
But in fact I want the content of my-project directly, not inside my-project directory.
What should I do ?
Don't bother with the git init at all: git clone means:
Make a directory, and enter that directory, so that all of the remaining five steps occur in that directory.
Run git init.
Run git remote add origin url, where the url comes from the git clone argument. You can change this name from origin to some other name, but you didn't.
Run any necessary git config operations (you didn't list any extra configurations to apply so this step doesn't do anything in your case).
Run git fetch origin.
Run git checkout name, where the name comes from the -b argument you gave to git clone. You didn't give one, so instead, name comes from the recommendation that the other Git over at origin gives. Most other Gits recommend master.
Note that step 2 does its own git init, so that's why you should not be doing one yourself. (If you like, you can run all six steps yourself, one at a time. Note that if you do that, you'll wind up in the directory you made. When git clone makes the directory and enters it, that doesn't move you, so this is slightly different.)
(In general, you should not be running any Git command with sudo. You might have some particular reason for doing that, but in general you should find some way to avoid doing that.)

How can i set up the ssh to my computer for github?

I have tried to set up my ssh with this tutorial but not work I always have the same error. How i can set up it?
I have these keys:
user#LAPTOP-LC8KG6GU MINGW64 ~/Documents/programmi_prove/helloworld_project (master)
$ ls -al ~/.ssh
total 32
drwxr-xr-x 1 user 197609 0 giu 17 16:02 ./
drwxr-xr-x 1 user 197609 0 giu 17 17:13 ../
-rw-r--r-- 1 user 197609 3389 giu 17 23:12 id_rsa
-rw-r--r-- 1 user 197609 748 giu 17 23:12 id_rsa.pub
These are my errors:
user#LAPTOP-LC8KG6GU MINGW64 ~/Documents/programmi_prove/helloworld_project (master)
$ git remote add origin https://github.com/speranza493/firstapp.git
fatal: remote origin already exists.
user#LAPTOP-LC8KG6GU MINGW64 ~/Documents/programmi_prove/helloworld_project (master)
$ git remote add origin https://github.com/speranza493/firstapp.git/
fatal: remote origin already exists.
user#LAPTOP-LC8KG6GU MINGW64 ~/Documents/programmi_prove/helloworld_project (master)
$ git push -u origin master
remote: Repository not found.
fatal: repository 'https://github.com/speranza493/firstapp.git/' not found
Did your repo url change? use git remote rm origin to remove the remote and then readd it with git remote add origin YOURURLHERE

Docker on Windows permission denied when git stash a file

With the latest version of Docker for Windows.
I got a php git repository that 2 of my containers use.
I modify a random file on the host : README.md
Then I do these git command one after the others :
git stash # ok
git stash pop # ok
git stash # ok
git stash pop # ok
git stash : => Takes 1 minute, then :
error: unable to create file README.md: Permission denied
fatal: Could not reset index file to revision 'HEAD'.
I also noticed that from inside the container :
root#317635dc4f03:watch -n 1 head README.md
Every 1.0s: head README.md
Thu Aug 10 16:27:37 2017
head: cannot open 'README.md' for reading: Stale file handle
Then
head: cannot open 'README.md' for reading: No such file or directory
On the Window host the file is visible but I can't open it neither delete it (permission denied)
I need to stop docker, stop the Hyper-V MobyLinuxVM, and wait to be able to restore the README.md file with a git reset --hard
Is there any way to avoid this kind of file sharing problem ?
Docker 17.06.0-ce |
Windows 10 pro : 15063.540 |
Hyper-V : 10.0.15063.0 |
Moby, trusty,

setting up ssh-keys for bitbucket account (with mac osx)

I have a BitBucket account. Despite setting up the ssh key on the computer and then adding it on my bitbucket account, I fail at connecting:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I did the following:
$ cd ~/.ssh
$ ssh-keygen -f ~/.ssh/my-key -N ''
$ vim config
Host bitbucket.org
HostName bitbucket.org
IdentityFile ~/.ssh/my-key
$ ls -l
-rw------- 1 me ... 229 Jul 8 15:50 config
-rw------- 1 me ... 1679 Jul 8 14:07 my-key
-rw-r--r-- 1 me ... 411 Jul 8 14:07 my-key.pub
Then I added the content of my-key.pub in my bitbucket account's ssh keys. Then I retried cloning my repository:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I repeated the identical procedure on another machine, it worked:
$ git clone git#bitbucket.org:my-account/myrepo.git
Initialized empty Git repository in /home/me/.ssh/myrepo/.git/
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
I need to do the same on my first machine now.
As a last resort, I followed some advises on the net using the ssh-agent:
$ eval `ssh-agent -s`
$ ssh-add ~/.ssh/my-key
But still no luck:
$ git clone git#bitbucket.org:my-account/myrepo.git
Cloning into 'myrepo'...
conq: repository does not exist.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I have no idea what is different on the first machine, why does it reject my request?
EDIT 1
Of course I tried doing it the very basic way, as suggested by D.Samchuk:
Generating the id_rsa
$ ssh-keygen -t rsa
enterx3
Copied the exact content of the key
$ cat ~/.ssh/id_rsa.pub
And I added id_rsa.pub's content in my BitBucket account's ssh keys.
Git clone will still not allow me to access the repository, whit the same output error message as above.
EDIT 2
I have no idea maybe it is related to mac configurations? Since The other machine is a redhat linux I just wondered but couldn't find any reported similar issue.
just do following:
$ ssh-keygen -t rsa
name: id_rsa
passphrase: just press enter twice to avoid print keyword everytime you connect
$ cat ~/.ssh/id_rsa.pub
copy output
open bitbucket --> profile --> bitbucket settings --> add ssh key --> paste your output
If you are not using a passphrase for the ssh key you shouldn't need the ssh-agent
https://help.github.com/articles/working-with-ssh-key-passphrases/
Solved. As I delved deeper in the issue I found it is absolutely not related to ssh keys but to missing repository as the error message suggested. It was all about experimenting the global config using git config --global that messed up my git configuration on that computer. I detailed my steps in another thread here: https://unix.stackexchange.com/questions/294780/git-retains-remote-information-from-a-deleted-repository/294809#294809.

"(.hg not found)" when cloning from cygwin-hosted repository via ssh to Mac and FreeBSD clients

I am running an archival filesystem on a Windows server that does automatic offsite replication which makes it the ideal place to host Mercurial repositories and be sure of their safety. This filesystem is Windows-only so I have no choice but to use Windows as the host OS.
Setup:
Server ('ungoliant', internal to my network):
Windows 7 master repository host machine.
Cygwin ssh daemon.
hg 1.9.3
Created new repository "/cygdrive/j/mercurial/rcstudio" on Windows with "hg init".
Clients:
Mac OSX 10.7.4 running hg 2.1.2
FreeBSD 8.3 running hg 2.1.2
Problem on Clients (identical on Mac and FreeBSD):
$ hg clone ssh://cjp#ungoliant//cygdrive/j/mercurial/rcstudio
running ssh cjp#ungoliant 'hg -R /cygdrive/j/mercurial/rcstudio serve --stdio'
remote: abort: There is no Mercurial repository here (.hg not found)!
abort: no suitable response from remote hg!
I've confirmed that the path and the URI are correct. There absolutely is an ".hg" directory there:
$ ls -la
total 0
drwxr-xr-x 3 cjp staff 102 Jun 5 17:41 .
drwxr-xr-x 41 cjp staff 1394 Jun 5 16:30 ..
$ scp -r cjp#ungoliant:/cygdrive/j/mercurial/rcstudio/.hg .
$ ls -la
total 0
drwxr-xr-x 3 cjp staff 102 Jun 5 17:41 .
drwxr-xr-x 41 cjp staff 1394 Jun 5 16:30 ..
drwxr-xr-x 5 cjp staff 170 Jun 5 17:41 .hg
$ ls -la .hg
total 16
drwxr-xr-x 5 cjp staff 170 Jun 5 17:41 .
drwxr-xr-x 3 cjp staff 102 Jun 5 17:41 ..
-rw-r--r-- 1 cjp staff 57 Jun 5 17:41 00changelog.i
-rw-r--r-- 1 cjp staff 33 Jun 5 17:41 requires
drwxr-xr-x 2 cjp staff 68 Jun 5 17:41 store
I've found plenty of stackoverflow questions where the issue was an improperly formatted ssh URI ... mine is formatted correctly and describes an absolute path.
I have confirmed all the following:
hg commands run fine both on the server and through ssh.
If I paste the absolute path I am able to confirm the existence of the .hg directory through ssh.
Other hg commands manually issued through ssh succeed (e.g.: ssh cjp#ungoliant 'cd /cygdrive/j/mercurial/rcstudio; hg diff;').
On the host machine I can clone locally from that same absolute path.
I'm stumped here. The Mercurial docs make it sound like 2.1.2 should be able to clone from 1.9.3 parents, so it doesn't appear to be a version conflict.
Would very much appreciate your help! Thanks!
What I have ended up with is a workaround and not an answer.
My own ignorance of remote ssh command processing lead to a misunderstanding. If I would ssh to the machine, "which hg" resulted with the cygwin-aware binary "/usr/bin/hg", but if I did a remote command "ssh cjp#ungoliant 'which hg'", it returned the path to a windows binary I also have installed on that machine.
I played with my .bashrc file and could not get remote command execution to prioritize the cygwin binary. The PATH doesn't even include the Windows PATH entries, so I started hacking around the problem and eventually decided to stop fighting with it.
I have since abandoned the entire idea because I'm convinced that even if I get it to work it will be a delicate kludge and not at all worth the time I've spent on it. I now host my repositories on a BSD box and I have a cron on the Windows machine that pulls from that repository onto the archival filesystem once every 24 hours. It's simple and worked like a charm with zero problems.
I had the same issue, solved it by adding the option --remotecmd like this
hg clone --remotecmd /usr/bin/hg ssh://me#mywindowspc//cygdrive/m/hgrepo
When you attempt an scp you would do the following:
scp username#ipaddr:/cygdrive/d/test/foo.txt ./myDestFolder
Unfortunately for hg that does not work. Instead try:
hg clone ssh://username#ipaddr/D:/testRepo

Resources