Jenkins: Multiple Git repositories for one project
Asked Answered
J

6

39

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).

Jinnah answered 14/5, 2013 at 8:17 Comment(1)
This is very similar to #14844196Eupatrid
P
31

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.

Polio answered 14/5, 2013 at 8:50 Comment(1)
The Multiple SCMs Plugin is now listed as deprecated.Codger
I
18

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

Ilan answered 21/6, 2013 at 14:49 Comment(0)
C
12

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'
      }
    }   
  }
}
Codger answered 20/8, 2016 at 16:0 Comment(1)
This should be the accepted answer! You saved my life.Doublure
S
2

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

Strontian answered 12/2, 2014 at 6:19 Comment(0)
P
1

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.

Philbert answered 14/9, 2023 at 18:23 Comment(1)
This works for my freestyle project without any further modifications (like switching to writing a pipeline), great! By the way, the Credentials plugin is currently installed on 97.4% of Jenkins instances, so this should work in most cases.Emee
A
0

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.

Azeotrope answered 28/2, 2018 at 20:55 Comment(1)
I realise this is an answer for an old question, but I came across the question with the same issue and found a solution.Azeotrope

© 2022 - 2024 — McMap. All rights reserved.