Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get multiple Jenkins builds to work from one local git repo?

Tags:

git

jenkins

I have a GitHub repo that's big and contains several independently build-able bits. If I configure Jenkins with a job (or two) for each of these, I end up with having to pull gigabytes of data multiple times (one clone of the repo for each job).

This takes both diskspace and bandwidth.

What I'd like to do is have "Refresh local repo" job that clones github once, then configure each of the jobs to clone themselves from that repo, and build. Then by setting up the sub-jobs as dependent builds, I can run "Refresh local repo", have it pull all the latest stuff from GitHub, then have each of the builds run.

So far I've got the "Refresh local repo" working - it clones successfully, and if I go to the workspace, I see that it has the HEAD commit of origin/master.

The problem is the other jobs - these don't seem to be picking up updates. Here's how I've got one of them configured:

Git  Repository URL file:////Users/malcolmbox/.jenkins/jobs/Refresh Local repo/workspace  Branches to build  master 

Instead of this updating to the latest commit, it's stuck several days in the past.

How can I get it to pull the tip and do the right thing?

To clarify: the .../Refresh Local repo/workspace has commit 6b20268389064590147d5c73d2b6aceb6ba5fe70 submitted 28/3

The dependent build, after running a build (so presumably doing a git clone/pull step) is checked out to 79a25992cc192376522bcb634ee0f7eb3033fc7e submitted 26/3 - so it's a couple of days behind.

like image 751
Malcolm Box Avatar asked Mar 28 '12 19:03

Malcolm Box


People also ask

How do I use local git repository in Jenkins?

Access local git repository in Jenkins docker container 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. The :ro option is optional.

Can we use multiple git repos in a single Jenkins job?

Checking out more than one repo at a time in a single workspace is possible with Jenkins + Git Plugin (maybe only in more recent versions?). In section "Source-Code-Management", do not select "Git", but "Multiple SCMs" and add several git repositories.

Can I have multiple local git repositories?

However, git is great for working with several repositories. These additional repositories can be stored locally, or accessed via network connection.

How can you clone a repository via Jenkins?

Configuring Git with Jenkins Now open your project and go to configure. Step 2: Give the repository Url in Source Code Management, repository Url can be fetched by clicking on clone and download option of Github and you have to select the SSH Url. Also, add credentials there of Jenkins.


1 Answers

If you open the job configuration and click on the Advanced button of the git SCM configuration, you will see a place to specify "Path of the reference repo to use during clone (optional)".

If you have a local clone of your repository, add the path to the reference repo field.

Git will then use the local clone and share most of the git objects on the disk and pulling from github only what is missing from the local clone resulting in lightning fast clones and saved disk space.

Or is this exactly how you have configured your job and it is not picking up latest commits? If that is so, please provide more details. Consider publishing your job configuration.

like image 85
sti Avatar answered Oct 30 '22 02:10

sti