簡體   English   中英

Jenkins具有多個倉庫的多分支管道,僅用於更改的倉庫

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM