viebel viebel - 1 year ago 250
Git Question

In Jenkins, how to checkout a project into a specific directory (using GIT)

Sorry for the 'svn' style - we are in a process of migration from SVN to GIT (including our CI Jenkins environment).

What do we need is to be able to make Jenkins to checkout (or should I say clone?) the GIT project (repository?) into a specific directory. We've tried some refspecs magic but it wasn't to obvious to understand and to use successfully.

Furthermore, if in the same Jenkins project we need to checkout several private GitHub repositories into several separate dirs under a project root. How can we do it please?

We have GitHub plugin installed. Hope we've phrased the things right.

Answer Source

The default git plugin for Jenkins does the job quite nicely.

After adding a new git repository (project configuration > Source Code Management > check the GIT option) to the project navigate to the bottom of the plugin settings, just above Repository browser region. There should be an Advanced button. After clicking it a new form should appear, with a value described as Local subdirectory for repo (optional). Setting this to folder will make the plugin to check out the repository into the folder relative to your workspace. This way you can have as many repositories in your project as you need, all in separate locations.

Alternatively, if the project you're using will allow that, you can use GIT sub modules, which are similar to external paths in SVN. In the GIT Book there is a section on that very topic. If that will not be against some policy, submodules are fairly simple to use, giving you powerful way to control the locations, versions/tags/branches that will be imported AND it will be available on your local repository as well giving you better portability.

Obviously the GIT plugin supports checking out submodules, so Jenkins can work with them quite effectively.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download