Need to clone repository after SSH into server using TeamCity - continuous-integration

I have a job that SSH into server and after that I need to git clone repository into this server that I SSHed before. How could I do it?
I set VCS checkout mode on agent, and set custom path

I think there are two ways to achieve it:
Use SSH Exec runner to execute git clone on remote machine
Use SSH Upload to upload previously cloned repository to remote machine
First one is faster but you need to take care of git auth on remote machine.

Related

Setting up Git Server on windows remote computer

I want to perform CI/CD on remote server running on windows for hosting my VueJs project. For doing that I have performed the following steps
I have added my ssh of my local machine to remote server as authorised keys and I am able to access the admin(cmd) remote server via ssh by using the following command.
ssh remote_server#<ip_address>
Using the above command the git bash opens cmd with following location c:/users/remote_user1 of remote server where I had added ssh of my local machine as authorized key.
I created bare git repo in C:/users/remote_user1 by logging in remote computer by rdp using the following command
git init test.git --bare
I gave Full access rights to test.git from remote server
I tried to clone test.git on my local machine using the command from git bash
git clone ssh://remoteserver#<ip_address>:/test.git
when I use the command from my local machine I get the error message from git bash
fatal: ''/test.git'' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I am not able to understand what am I am doing wrong here, Please guide me on this.
The format for ssh urls must be one of :
# 'ssh://' url :
ssh://remoteserver#<ip_address>/test.git
# scp-like syntax :
remoterserver#<ip_address>:test.git
(link to docs)
The url you posted contains a :/ which makes it a mixture of both, you should modify this url to match one of the two accepted formats.

Specify SSH credentials/keys in Windows Git under Jenkins user

I am using Jenkins in our builds
So I am already using the GIT Plugin
This plugin lets me specify Jenkins credentials, where we have already specified and installed/setup SSH keys.
However at the end of the build, I'd like to git tag my repo. I am calling the git.exe command line, and I get this error on a push:
Permission denied (publickey).
fatal: Could not read from remote repository.
Ideally, we don't want to use another plug in, (e.g. Git Publisher), as we are trying to do more of this via our own scripts as there is a good possibility that we may not use Jenkins in the future.
Also, ideally, we don't want to install items on our build server if we don't have to.
So the question is - how can I specify ssh keys/credentials on the command line for the given 'session'?
Thank you.
Put this in a shell script:
ssh -i path-to-your-private-key
Set the path to the shell script in GIT_SSH for Jenkins. git pull will then use that instead of plain ssh to access the remote repository.
Alternately you could configure ssh in $HOME/.ssh for the account under which Jenkins runs, but that can get tricky if your Jenkins runs as a Windows service.

Git how to access repository Windows local machine?

I installed Git for Windows in order to clone and pull a project hosted on a remote Linux server.
In my repository (D:/repositories/my-project) I launch the following commands
git clone server#192.168.56.101:/var/www/web/my-project/.git
git pull origin master
So far so good. I pull the project files whenever modifications are applied on the server.
But now I'd like to pull or push from the remote server to my local repository.
I tried many things but I can't figure out how to access the repository located on my local machine.
Things like:
git pull duddy#my-pc:/d/repositories/my-project/.git master
just doesn't work, Git says:
ssh: Could not resolve hostname my-pc: Name or service not known
fatal: Could not read from remote repository.
Can someone helps me ?
First things first, I would recommend you try simply running git pull.
If this doesn't work, try running git remote -v and check to make sure that the URL for your server is listed as an origin (server#192.168.56.101:/var/www/web/my-project/.git).
Your issue is that you are inputting the URL for your local repository in your attempt to git pull.
I suggest reading the git-pull documentation to learn more about how pull works.
Basically, you need to have some service at your workstation which serves the requests. There are following options (I did not try most of them myself, just making it up from what I know):
use the windows file access. This is the easiest to setup at the windows workstation - just share the repository folder. The Linux side should somehow be able to mount windows shares (like described, for example, here: https://wiki.ubuntu.com/MountWindowsSharesPermanently). If you manage to mount your \\my-pc\repo to some /mount/my-pc-repo, then you can access it as file:///mount/my-pc-repo.
run git daemon at windows. Set up instructions are available at SO (for example, https://stackoverflow.com/a/2275844/2303202) and it pretty straightforward, but it does not have any authentication and in most cases it is reasonable to use it only for reading, so you will not be able to push to the workstation, only fetch.
set up ssh daemon and access through ssh authentication with read-write access. Git for windows installation contains the needed software (the sshd.exe binary, it is there at least for Git for Windows 2.6.0), probably there is a way to utilize it but I could not find it quickly.
set up HTTP(S) service at your workstation. I don't know if it is possible to do only with Git for Windows (it might be, with some perl module which happen to be included with it), or you should use some other software.

Installing git on remote server and pushing local repository

I know this question has probably been asked a few times but I can't find an exact example of what i'm looking to do and for some reason I can't seem to get it to work.
I have a local ruby on rails repo i'm ready to share with another developer, could someone give me a run through(or point me in the right direction) of creating the new repository by PUSHING my local repo up to it?
Thanks
Marc
I would highly recommend bitbucket (Free up to 5 users) as a hosted git service. They have great documentation:
EDIT:
create repo
https://confluence.atlassian.com/display/BITBUCKET/Create+a+repository
push
https://confluence.atlassian.com/display/BITBUCKET/Import+code+from+an+existing+project
If you want to manage your own remote git repo, then
Make a bare clone of the repo
git clone --bare my_git_project my_git_project.git
Copy the bare repo to remote server
scp -r my_git_project.git gituser#remoteserver.com:/opt/git
Then login to the remote server and go to the git folder
ssh gituser#remoteserver.com
cd /opt/git/my_git_project.git
Then run this command
git init --bare --shared
At this point, any user who has ssh access to the remoteserver.com and write permissions on /opt/git/my_git_project.git will also have push access
A software such as Open source GitlabHQ is highly recommended if you wish to manage your own git hosting. Gitlab also has a hosted version gitlab cloud with unlimited free private repos and unlimited collaborators. Of course they also have paid version.

How to git clone a repo in windows from other pc within the LAN?

I have this git repo "c:/xampp/htdocs/**" in my main PC and its IP address is 192.168.0.6. Now I want to git clone this repo from ubuntu-server which running on a Vmware Player in my main PC.
I did
git clone \\192.168.0.6\c:\xampp\htdocs\****
and
git clone //192.168.0.6/c:/xampp/htdocs/****
from ubuntu-server and neither worked.
fatal: could not create work tree dir '****'.: Permission denied
What did I wrong?
what should I do?
You should use the command git daemon to host your repo, like this:
In your computer that will act as a server:
git daemon --base-path=<path_to_folder_containing_project_folder> --export-all
(please note that path_to_folder_containing_project is the folder containing your projects folders, it will provide all projects under that folder)
In your client:
git clone git://<local ip>/<project name>
The cloned repo will have its origin pointing to the server in your LAN, so you may want to use git remote set-url origin to point it to the original origin.
You may want to run git daemon with the --verbose option to get more details in case you run into problems.
Make sure that your c:/xampp/htdocs folder (or sub folders of it) is shared in windows, so you can navigate on the network by this address:
\\192.168.0.6\htdocs
Then you clone by using file:////. Note that there are four slashes:
git clone file:////192.168.0.6/htdocs/somerepo.git
To access the repo, you must either share it on 192.168.0.6 or must be the same domain user as the one that owns the file on 192.168.0.6.
If you share the directory on 192.168.0.6 (e.g. with share name myrepo), you access it with //192.168.0.6/myrepo.
If you are logged in on your box with a user accout that is known on 192.168.0.6, you could try accessing the repo through the administrative shares:
//192.168.0.6/c$/xampp/htdocs/...
Always use forward slashes.
Another alternative would be using SSH to access the remote machine.
Using explorer (smb) to mount the remote repository as a network share is the easiest way. I'm not entirely sure, but I think you paths might be wrong. Try file:///192.168.0.6\c:\xampp... instead.
There are two things that might have gone wrong for you:
You don't have read permission on the remote repository
You don't have write permission in the location you want to create your repository ( the current working directory or the directory you specify as second argument to git clone)
And also check if your samba server works for normal file access.
To make git repo on Windows local network you'd need to do the following:
Create new repo
git init --bare projectName.git
Share this folder (projectName.git) with the users you need
Find your PC ip with ipconfig command (e.g. 192.168.2.101)
Run this command from some user's machine
git clone //192.168.2.101/projectName.git
Note: open \\192.168.2.101 in finder to see the correct path to the projectName.git (e.g. //192.168.2.101/some/path/projectName.git)
I recently ran into this error while trying to clone a repository in a remote pc to a local pc within the same LAN network.
The solution was to first make sure the drive location in the remote pc had the correct access rights for the local PC(Read/Write-which can be set using windows sharing options)
Copy the path of the remote repository. In your local pc paste the path in a windows explorer window. Then copy its directory address and paste it into any browser.
Now you should get a link with the hostname and the correct cloning URL format.
Use this link to clone the repository in the local pc.
Hope this helps.
Cheers.
"I have a few different computers that I use at home and I wanted to set up GIT that I can access my code from any of them. It took me a bit because I was too used to working with a client-server model where I designate one machine as the "server" that holds the repository and everything else was a client. Instead, GIT seems to operate more like a merge tool and every local copy is its own "master." Once I understood that, it turns out that setting up GIT is very simple and just needs GIT itself and SSH".
To read more you can check this link:
http://blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html

Resources