我正在使用 Jenkins 管道插件和 Jenkinsfile。
在一个名为 vms.git 的存储库中,我有 Jenkinsfile 和它构建的一个应用程序。
我有另一个名为 deploy.git 的存储库,其中包含我想用来在 vms.git 中部署应用程序的脚本。
目前我的 Jenkinsfile 看起来像这样
node {
stage 'build'
checkout scm
我正在作业配置中定义 vms.git 存储库。
所以我想做的是检查两个存储库,然后使用 vms.git 中的 Jenkinsfile 来定义构建的其余部分。我想在其他管道中重用 deploy.git 脚本,所以我不想在其中放置 Jenkinsfile。
最佳答案
您可以使用checkout
check out 多个目录,但您必须指定要 check out 的目录。您可以使用 jenkins 生成代码片段(代码片段生成器在脚本字段下方)。
选择 checkout ,下一个 git 存储库,并在其他行为中选择: checkout 到子目录。
当您将拥有 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 - 带有两个 git 存储库的 Jenkinsfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37395860/