Checkout multiple git repos into same Jenkins workspace Checkout multiple git repos into same Jenkins workspace jenkins jenkins

Checkout multiple git repos into same Jenkins workspace


With the Multiple SCMs Plugin:

  • create a different repository entry for each repository you need to checkout (main project or dependancy project.

  • for each project, in the "advanced" menu (the second "advanced" menu, there are two buttons labeled "advanced" for each repository), find the "Local subdirectory for repo (optional)" textfield. You can specify there the subdirectory in the "workspace" directory where you want to copy the project to. You could map the filesystem of my development computer.

The "second advanced menu" doesn't exist anymore, instead what needs to be done is use the "Add" button (on the "Additional Behaviours" section), and choose "Check out to a sub-directory"

  • if you are using ant, as now the build.xml file with the build targets in not in the root directory of the workspace but in a subdirectory, you have to reflect that in the "Invoke Ant" configuration. To do that, in "Invoke ant", press "Advanced" and fill the "Build file" input text, including the name of the subdirectory where the build.xml is located.

Hope that helps.


Checking out more than one repo at a time in a single workspace is not possible with Jenkins + Git Plugin.

As a workaround, you can either have multiple upstream jobs which checkout a single repo each and then copy to your final project workspace (Problematic on a number of levels), or you can set up a shell scripting step which checks out each needed repo to the job workspace at build time.

Previously the Multiple SCM plugin could help with this issue but it is now deprecated. From the Multiple SCM plugin page: "Users should migrate to https://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin . Pipeline offers a better way of checking out of multiple SCMs, and is supported by the Jenkins core development team."


Since Multiple SCMs Plugin is deprecated.

With Jenkins Pipeline its possible to checkout multiple git repos and after building it using gradle

node {   def gradleHomestage('Prepare/Checkout') { // for display purposes    git branch: 'develop', url: 'https://github.com/WtfJoke/Any.git'    dir('a-child-repo') {       git branch: 'develop', url: 'https://github.com/WtfJoke/AnyChild.git'    }    env.JAVA_HOME="${tool 'JDK8'}"    env.PATH="${env.JAVA_HOME}/bin:${env.PATH}" // set java home in jdk environment    gradleHome = tool '3.4.1' }stage('Build') {  // Run the gradle build  if (isUnix()) {     sh "'${gradleHome}/bin/gradle' clean build"  } else {     bat(/"${gradleHome}\bin\gradle" clean build/)  }}}

You might want to consider using git submodules instead of a custom pipeline like this.