【发布时间】:2018-12-24 05:17:32
【问题描述】:
所以,我确实有一个复杂的存储库结构(至少我认为是这样),我需要在那里实现 CI-CD。我所有的 webhook 和设置都已完成,现在我被部署部分困住了。
所以我有 4 个不同的存储库,它们最终为整个生产构建了一个 tar 文件。
Repo1: https://gitlab.example.com/repo1
Repo2: https://gitlab.example.com/repo2
Repo3: https://gitlab.example.com/repo3
Repo4: https://gitlab.example.com/repo4
我在每个 repo 的根目录下都有 JenkinsFile(每个项目下都有相同的 Jenkinsfile)。
这是我的 git checkout 管道脚本的片段:
properties ([
[$class: 'GitLabConnectionProperty', gitLabConnection: 'gitlab'],
pipelineTriggers([[
$class: "GitLabPushTrigger",
triggerOnPush: true,
triggerOnMergeRequest: true,
// triggerOpenMergeRequestOnPush:"both",
triggerOnNoteRequest: true,
noteRegex: "CI BUILD THIS AGAIN",
// skipWorkInProgressMergeRequest: true,
// ciSkip:false ,
//setBuildDescription: true,
addNoteOnMergeRequest:true,
addCiMessage: true,
addVoteOnMergeRequest: true,
acceptMergeRequestOnSuccess: true,
//branchFilterType: "NameBasedFilter",
//targetBranchRegex: "feature-decc-changes",
//includeBranchesSpec: "feature-decc-changes,master,stage,prod",
excludeBranchesSpec: "dev"
]])
])
stage('CHECKOUT: Checkout the Repos '){
steps {
checkout([$class: 'GitSCM', branches: [[name: "**"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '$BUILD_NUMBER/node']],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${GIT_SSH_KEY_ID}",
url: 'git@gitlab.example.com:repo1.git']]])
checkout([$class: 'GitSCM', branches: [[name: "**"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '$BUILD_NUMBER/angular']],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${GIT_SSH_KEY_ID}",
url: 'git@gitlab.example.com:repo2.git']]])
checkout([$class: 'GitSCM', branches: [[name: "**"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '$BUILD_NUMBER/common']],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${GIT_SSH_KEY_ID}",
url: 'git@gitlab.example.com:repo3.git']]])
checkout([$class: 'GitSCM', branches: [[name: "**"]],
doGenerateSubmoduleConfigurations: false,
extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: '$BUILD_NUMBER/extra']],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: "${GIT_SSH_KEY_ID}",
url: 'git@gitlab.example.com:repo4.git']]])
}
}
对于任何分支中的任何更改,它正在创建构建并从 repo 中随机检查任何分支并创建构建。
但我希望 jenkins 检查刚刚更改的分支。例如。如果我在 repo2 下将更改推送到“feature-abc”分支,它应该从 repo2 和所有其他 repo 中签出分支“feature-abc”。此外,如果 feature-abc 分支不存在,请从自定义 repo(例如默认 master)中签出。
如果我不清楚,请告诉我。我会尽力提供更多信息。
【问题讨论】:
标签: git jenkins github continuous-integration jenkins-pipeline