簡體   English   中英

詹金斯:使用不同的分支構建多個存儲庫

[英]Jenkins: Building multiple repos with different branches

我有多個帶有自己的 jenkins 文件的存儲庫,當我在處理一個存儲庫時,我需要構建其他存儲庫,因此我部署了端到端應用程序以進行功能開發。 由於應用程序在 AWS 上運行,並且容器部署到 EKS,我的偏好是能夠在 AWS 上構建和運行。

構建有一個順序,首先需要部署基礎設施,然后是后端服務(有3個)和UI。

理想情況下,我可以選擇部署 5 個存儲庫中的哪些分支,並且當作為臨時環境的一部分部署的任何分支發生更改時,管道將觸發。

到目前為止,我在想的是在每個 repo 中都有一個 jenkinsfile 並創建第 6 個 repo,它只有一個 yaml 文件和自己的 jenkinsfile。 此 repo 的管道作業將從 yaml 文件中獲取有關要使用哪些分支的數據,並觸發其他管道將分支傳遞給每個管道,這將是唯一具有實際管道作業的 repo。

有沒有人試過這個? 我不確定是否有可能讓管道監視多個不同的存儲庫和分支並充當協調器,啟動其他管道。

可能有一種更簡單的方法可以做到這一點,我已經閱讀了很多帖子和文章,但似乎沒有一個能達到我想要的效果。

一種方法是通過將每個 repo 的所有階段組合到這個單個 Jenkinsfile 中來編寫單個 Jenkinsfile

stages {
  stage('Infra Setup') {
    steps {
      
      // The below will clone your repo and will be checked out to master branch by default.
      git credentialsId: 'jenkins_git_cred', url: '<your_git_url_for_clone>'
      sh "git checkout branchname"
      // Your steps 
    }
  }

  stage('Backend1 ') {
    steps {
     //If you want to checkout to a specific branch by default instead of master then use the below in your pipeline stage. 
    checkout([$class: 'GitSCM', branches: [[name: '*/branchname']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'jenkins_git_cred', url: 'your_git_url_for_clone']]])
    }
  }

  stage('backend_n') {
    steps {
      // One or more steps need to be included within the steps block.
    }
  }

  stage('UI') {
    steps {
      // One or more steps need to be included within the steps block.
    }
  }

}

您可以使用 jenkins pipeline-syntax https://your-jenkins-url.com/pipeline-syntax/生成語法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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