带有两个git存储库的Jenkinsfile
我正在将Jenkins管道插件与Jenkinsfile一起使用。
在一个名为vms.git的存储库中,我有Jenkinsfile及其构建的应用程序。
我还有一个名为deploy.git的存储库,其中包含我想用于在vms.git中部署应用程序的脚本。
目前,我的Jenkinsfile看起来像这样
node { stage 'build'
checkout scm
并且我在作业配置中定义了vms.git存储库。
因此,我想做的是检出两个存储库,然后使用vms.git中的Jenkinsfile定义其余的构建。我想在其他管道中重用deploy.git脚本,所以我不想在其中放置Jenkinsfile。
回答:
您可以使用来签出多个目录checkout
,但是必须指定要在其中签出的目录。您可以使用jenkins生成代码段(代码段生成器下面的脚本字段)。选择签出,下一个git存储库,然后在“其他行为”中选择:签入子目录。
当您有2个存储库时,可以从想要使用的存储库中加载脚本load
。例:
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 的全部内容, 来源链接: utcz.com/qa/418116.html