Jenkins: Multiple Git repositories for one project

2019-01-23 01:14发布

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

5条回答
Juvenile、少年°
2楼-- · 2019-01-23 01:40

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'
      }
    }   
  }
}
查看更多
走好不送
3楼-- · 2019-01-23 01:48

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.

查看更多
霸刀☆藐视天下
4楼-- · 2019-01-23 01:49

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

查看更多
男人必须洒脱
5楼-- · 2019-01-23 01:56

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.

查看更多
在下西门庆
6楼-- · 2019-01-23 01:58

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

查看更多
登录 后发表回答