Mihai
Mihai

Reputation: 2155

Jenkins: Multiple Git repositories for one project

I want to build a project using two Git repositories. One of them contains of the source code, while the other has the build and deployment scripts.

My problem is that I need to have a repository for building and deployment of different parts of the project (big project, multiple repositories, same build and deployment scripts), but Jenkins does not seem to be able to handle this (or I don't know/didn't find how).

Upvotes: 39

Views: 25623

Answers (6)

EpicVoyage
EpicVoyage

Reputation: 754

If you are using the Credentials plugin and want to check out another Git repository during a build, you can follow these steps as of 2021:

  • Build Environment -> Use secret text(s) or file(s) -> Add Git Username and Password -> Select
  • Build Steps -> Add Execute shell, Execute Windows batch command, or PowerShell -> git clone https://...

If you are not using credentials, just create the script.

Upvotes: 1

enkor
enkor

Reputation: 7557

When you add another SCM via the Multiple SCM plugin and choose Git. You can specify to 'Check out to a sub-directory' via the 'Additional Behaviours' options for a repo. Thus you can have multiple repos in a workspace.

Upvotes: 0

carl verbiest
carl verbiest

Reputation: 1283

I had the same question, when I looked at the Multiple SCM plugin answer I noticed this plugin is now listed as deprecated. There is a notice that recommends to use a pipeline for this.

Below is a sample config of how I managed to do this with a pipeline.

node() {
  stage ('Extract') {
    parallel 'Extract':{
      dir('project1') {
        git url: 'ssh://git@githost/project1.git'
      }
      dir('project2') {
        git url: 'ssh://git@githost/project2.git'
      }
    }   
  }
}

Upvotes: 13

Petr Mensik
Petr Mensik

Reputation: 27496

UPDATE

Multiple SCMs Plugin is now deprecated so users should migrate to Pipeline plugin.

Old answer

Yes, Jenkins can handle this. Just use Multiple SCMs under Source Code Management, add your repositories and then go to the Advanced section of each repository. Here you need to set Local subdirectory for repo (optional) and Unique SCM name (optional).

Your repository will be pulled to the Local subdirectory which you have set so then you can build them in any order you want.

Updating per harishs answer - you need to install Multiple SCMs Plugin in order to achieve this functionality.

Upvotes: 31

Manu Garg
Manu Garg

Reputation: 21

Just sharing my experience when dealing with Multiple SCM. If you want to add multiple git repositories in your jenkins build, make sure that the other git plugin versions are compatible with Multiple SCM plugin. Here's a list of plugin with version which worked for me:

  • GitHub API Plugin 1.44
  • Jenkins GIT client plugin 1.6.2
  • Jenkins GIT plugin 2.0.1
  • Git Server Plugin 1.2
  • Multiple SCMs 0.2

Earlier I upgraded to Multiple SCM 0.3 and I was not able to add any git repo in that section.

Rgds, Manu

Upvotes: 2

harish
harish

Reputation: 1924

Answer from Petr Mensik is right but this does not seem to be available by default in Jenkins. One needs to install Multiple SCM plugin to get this feature: https://wiki.jenkins-ci.org/display/JENKINS/Multiple+SCMs+Plugin

Upvotes: 18

Related Questions