69

I'm new to Jenkins and git too. I created a remote repository at github.com and made a local copy of it.
Then I want to link it through Jenkins. I installed needed plugins for git integration, but I don't know what my local Repository URL is to set it when configuring the new project. Could someone help me where to find it?

simont
  • 68,704
  • 18
  • 117
  • 136
Zhivko Draganov
  • 1,213
  • 2
  • 10
  • 16

4 Answers4

100

In this case, the URL should start with the file protocol followed by the path to the repository. E.g., file:///home/rbkcbeqc/dev/git/gitsandbox.

ЯegDwight
  • 24,821
  • 10
  • 45
  • 52
  • 5
    See [git plugin for Jenkins fails to clone a repo from local machine](https://stackoverflow.com/questions/17307938/git-plugin-for-jenkins-fails-to-clone-a-repo-from-local-machine-error-code-128) if it doesn't work for you. – l0b0 Jan 10 '14 at 23:12
  • what about mac file system? Does the prefix file stay? – EugenSunic Jun 28 '23 at 20:46
24

Access local git repository in Jenkins docker container

In case somebody wants to connect to a local git repository from a Jenkins which runs in a docker container I would recommend to mount the local git repository folder to the docker image via the Volumes flag (see Use Volumes for more details).

To mount your local git repository folder to a Jenkins container run the container with an additional -v or --volume flag.

The basic docker run statement from the official docker image documentation would then look like.

docker run -p 8080:8080 -p 50000:50000 
           -v <PATH_TO_LOCAL_GIT_REPO>:<MOUNT_POINT_IN_CONTAINER>:ro 
           jenkins/jenkins:latest

The :ro option is optional. It will mount the volume as read-only. So you won't be able to write to the repos from the container.

Then you can simply access your git repository via the file protocol.

file:///<MOUNT_POINT_IN_CONTAINER>

No need to use ssh.

Paul Wasilewski
  • 9,762
  • 5
  • 45
  • 49
  • It seems this solution works, but when I make changes in my git repo on my host machine, they are not reflected in the mounted volume...so I can't really test out how Jenkins responds to changes I make as I go. Is that correct, or am I doing something wrong? – Seth Lutske Mar 29 '21 at 20:05
  • 1
    people who have problems please don't forget to add a slash after file//, like file:///var/project, there are 3 slashes – erdemlal Apr 21 '21 at 12:56
9

If you run Jenkins within Docker, one possible solution would be via SSH:

ssh://user@IP_of_your_host/path_to_your_project/project_name
eisbehr
  • 12,243
  • 7
  • 38
  • 63
Chuan
  • 3,103
  • 1
  • 19
  • 23
4

If you did clone a remote repository into local where Jenkins is running.

You can just put the path of the local repository then it will work.

For example, /home/username/local_repository_path.

SangminKim
  • 8,358
  • 14
  • 69
  • 125