带有两个 git 存储库的 Jenkinsfile [英] Jenkinsfile with two git repositories

查看:55
本文介绍了带有两个 git 存储库的 Jenkinsfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Jenkins 管道插件与 Jenkinsfile 一起使用.

I'm using the Jenkins pipeline plugin with a Jenkinsfile.

在一个名为 vms.git 的存储库中,我有 Jenkinsfile 和它构建的应用程序.

In one repository, called vms.git, I have the Jenkinsfile and an application it builds.

我有另一个名为 deploy.git 的存储库,其中包含我想用来在 vms.git 中部署应用程序的脚本.

I have another repository called deploy.git, which contains scripts I want to use to deploy the application in vms.git.

目前我的 Jenkinsfile 看起来像这样

At the moment my Jenkinsfile just looks like this

node {
  stage 'build'
  checkout scm

我正在作业配置中定义 vms.git 存储库.

and I am defining the vms.git repo in the job configuration.

所以我想做的是检查两个存储库,然后使用 vms.git 中的 Jenkinsfile 来定义构建的其余部分.我想在其他管道中重用 deploy.git 脚本,所以我不想在那里放一个 Jenkinsfile.

So what I would like to do is check out both repositories, then use the Jenkinsfile in vms.git to define the rest of the build. I want to reuse the deploy.git scripts in other pipelines so I don't want to put a Jenkinsfile in there.

推荐答案

您可以使用 checkout 检出多个目录,但必须指定您想要检出的目录.您可以使用 jenkins(代码段生成器波纹管脚本字段)生成代码段.选择结帐,下一个 git 存储库,然后在附加行为中选择:结帐到子目录.

You can checkout multiple directories using checkout, but you have to specify directory where you want checkout this. You can generate snippets using jenkins (Snippet generator bellow script field). Choose checkout, next git repository and in Additional Behaviours choose: checkout into sub directory.

当您有 2 个存储库时,您可以使用 load 从您想要的存储库加载脚本.示例:

When you will have 2 repositories you can load script from repository you want usin load. Example:

node {
    // first repository
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory1']], submoduleCfg: [], userRemoteConfigs: [[url: 'repo1.git']]])
    // second repository
    checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: 'subdirectory2']], submoduleCfg: [], userRemoteConfigs: [[url: 'repo2.git']]])
    // run first script
    load 'subdirectory1/Jenkinsfile'
    // run second script
    load 'subdirectory2/Jenkinsfile'
}

这篇关于带有两个 git 存储库的 Jenkinsfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆