Jenkins:一个项目的多个 Git 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16538198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:09:05  来源:igfitidea点击:

Jenkins: Multiple Git repositories for one project

gitdeploymentbuildjenkins

提问by Mihai

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.

我想使用两个 Git 存储库构建一个项目。其中一个包含源代码,而另一个包含构建和部署脚本。

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

我的问题是我需要有一个存储库来构建和部署项目的不同部分(大项目、多个存储库、相同的构建和部署脚本),但 Jenkins 似乎无法处理这个(或者我没有)不知道/没有找到如何)。

采纳答案by Petr Mensik

UPDATE

更新

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

多个 SCM 插件现已弃用,因此用户应迁移到Pipeline 插件

Old answer

旧答案

Yes, Jenkins can handle this. Just use Multiple SCMsunder 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).

是的,詹金斯可以处理这个。只需Multiple SCMs在源代码管理下使用,添加您的存储库,然后转到每个存储库的高级部分。在这里你需要设置Local subdirectory for repo (optional)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 Pluginin order to achieve this functionality.

更新每个harish答案 - 您需要安装多个 SCM 插件才能实现此功能。

回答by harish

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

Petr Mensik 的回答是正确的,但默认情况下在 Jenkins 中似乎不可用。需要安装Multiple SCM插件才能获得此功能:https: //wiki.jenkins-ci.org/display/JENKINS/Multiple+SCMs+Plugin

回答by carl verbiest

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.

我有同样的问题,当我查看 Multiple SCM plugin answer 时,我注意到这个插件现在被列为已弃用。有一条通知建议为此使用管道。

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'
      }
    }   
  }
}

回答by Manu Garg

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:

只是分享我在处理多个 SCM 时的经验。如果要在 jenkins 构建中添加多个 git 存储库,请确保其他 git 插件版本与 Multiple SCM 插件兼容。以下是对我有用的版本插件列表:

  • 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
  • GitHub API 插件 1.44
  • Jenkins GIT 客户端插件 1.6.2
  • 詹金斯 GIT 插件 2.0.1
  • Git 服务器插件 1.2
  • 多个单片机 0.2

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

早些时候,我升级到 Multiple SCM 0.3,但无法在该部分添加任何 git repo。

Rgds, Manu

Rgds, 马努

回答by enkor

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.

当您通过 Multiple SCM 插件添加另一个 SCM 并选择 Git 时。您可以通过存储库的“其他行为”选项指定“签出到子目录”。因此,您可以在工作区中拥有多个存储库。