Jenkinsfile与两个git存储库 [英] Jenkinsfile with two git repositories

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

问题描述

我使用Jenkins管道插件和Jenkinsfile。

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



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



目前我的Jenkinsfile看起来像这样

 节点{
stage'build'
checkout scm

我在作业配置中定义了vms.git repo。



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

解决方案

您可以使用 checkout 来检出多个目录,但是您必须指定要检出的目录。你可以使用jenkins生成片段(Snippet generator bellow script field)。
选择checkout,下一个git仓库,在Additional Behaviors中选择:checkout into sub directory。



当你有2个仓库时,你可以从你想要的仓库中加载脚本usin 载入。例子:

  node {
//第一个存储库
checkout([$ class:'GitSCM',分支:[[name:'* / master']],doGenerateSubmoduleConfigurations:false,extensions:[[$ class:'RelativeTargetDirectory',relativeTargetDir:'subdirectory1']],submoduleCfg:[],userRemoteConfigs:[[url:'repo1 .git']]])
//第二个存储库
checkout([$ class:'GitSCM',branches:[[name:'* / master']],doGenerateSubmoduleConfigurations:false,extensions:[ [$ class:'RelativeTargetDirectory',relativeTargetDir:'subdirectory2']],submoduleCfg:[],userRemoteConfigs:[[url:'repo2.git']]])
//运行第一个脚本
加载'subdirectory1 / Jenkinsfile'
//运行第二个脚本
load'subdirectory2 / Jenkinsfile'
}


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

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

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

At the moment my Jenkinsfile just looks like this

node {
  stage 'build'
  checkout scm

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

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.

解决方案

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.

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

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

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