因此,我确实有一个复杂的存储库结构(至少与我的想法相同),并且我需要在那里实现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
我在每个存储库的根部都有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']]])
}
}
这里任何分支中的任何更改都是创建构建,并从仓库中随机签出任何分支并创建构建。
但是我希望詹金斯结帐刚刚更改过的分支。对于exa。如果我将更改推送到repo2下的“ feature-abc”分支,则应从repo2和所有其他repo签出该分支“ feature-abc”。另外,如果feature-abc分支不存在,请从自定义存储库(例如默认主存储库)中检出。
如果不清楚,请通知我。我将尝试提供更多信息。
答案 0 :(得分:0)
根据我的理解...在仓库中推动分支,您将构建所有 所有其他存储库和此存储库中的相同分支
尝试viewDidAppear
,它将为您提供正在检出的分支(发生推送时)...这样您就可以检出其他存储库...
检出其他分支时,请检查该分支是否存在env.BRANCH_NAME
,如果它存在则将返回一个hashCode,如果不存在则从您的自定义存储库中获取它。
希望它会有所帮助:)