![](/img/trans.png)
[英]Jenkins multibranch pipeline build mysteriously setting origin to local repo
[英]Jenkins multibranch pipeline with multiple repo to build for the changed repo only
因此,我确实有一个复杂的存储库结构(至少与我的想法相同),并且我需要在那里实现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分支不存在,请从自定义存储库(例如默认主库)中检出。
如果不清楚,请告诉我。 我将尝试提供更多信息。
根据我的理解...在仓库中推动分支,您将在所有其他仓库和该仓库中建立所有相同的分支
尝试env.BRANCH_NAME
,它将为您提供正在检出的分支(当发生推送时)...这样您就可以检出其他存储库...
当检查其他分支时,检查该分支是否存在git ls-remote --heads git@github.com:user/repo.git existingbranch
它将返回一个hashCode(如果存在),如果不从您的自定义git ls-remote --heads git@github.com:user/repo.git existingbranch
获取它
希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.