使用同一项目中远程存储库的分支名称填充 azure Devops 管道参数

问题描述 投票:0回答:1

我们的应用程序使用多存储库结构。例如,在同一个 azure devops 项目中,我们有单独的存储库用于内部或外部门户等服务。

我创建了一个多阶段管道,该管道位于不同的存储库中,称为覆盖层,与内部或外部门户等服务分开,但位于同一项目中。这提出了一个挑战,当我运行这个管道时,它看不到其他存储库中存在的分支,例如内部门户。解决方法是将我的管道移至例如内部门户存储库,但这带来了另一个挑战。

当我们从主分支部署版本或从功能分支测试它们时,如果分支不存在(例如在外部门户中但存在于内部门户中),则管道将出错

Could not get the latest source version for repository

trigger: none

pool:
  vmImage: 'ubuntu-latest'

parameters:
- name: external_portal
  type: boolean
  default: false
- name: internal_portal
  type: boolean
  default: false

resources:
  repositories:
    - repository: templates
      type: git
      name: aks-templates/common-templates
      ref: refs/heads/main
    - repository: overlays
      type: git
      name: aks-microservices/overlays-and-services
      ref: refs/heads/main
     - repository: external-portal
       type: git
       name: aks-microservices/ExternalPortal
       ref: ${{ variables['Build.SourceBranch'] }}
    - repository: internal-portal
      type: git
      name: aks-microservices/InternalPortal
      ref: ${{ variables['Build.SourceBranch'] }}

variables:
  - group: common

stages:
 - ${{ if eq(parameters.external_portal, true) }}:
     - template: pipelines/templates/validate.yml@templates
       parameters:
         aksServiceName: 'external-portal'

- ${{ if eq(parameters.internal_portal, true) }}:
    - template: pipelines/templates/validate.yml@templates
      parameters:
        aksServiceName: 'internal-portal'

我的问题是:有没有办法创建一个参数并使用远程存储库中的现有分支列表填充它,以让用户选择他们想要部署的分支?

我尝试过“step”或“stepList”类型的参数,但运气不佳。

azure-devops azure-pipelines azure-pipelines-yaml
1个回答
0
投票

我建议您为外部和内部门户创建单独的管道。

您已经在使用模板 (

pipelines/templates/validate.yml@templates
),因此代码重复将最少(例如,复制一些
repository
资源)。但是,另一方面,您将能够独立运行每个管道并使用不同的分支。

内部Portal管道

内部门户管道的建议实施:

trigger: none

pool:
  vmImage: 'ubuntu-latest'

resources:
  repositories:
    - repository: templates
      type: git
      name: aks-templates/common-templates
      ref: refs/heads/main
    - repository: overlays
      type: git
      name: aks-microservices/overlays-and-services
      ref: refs/heads/main
    
    # Required? 
    # Can be removed if this pipeline is located in the same repository 
    # - repository: internal-portal
    #   type: git
    #   name: aks-microservices/InternalPortal
    #   ref: ${{ variables['Build.SourceBranch'] }}

variables:
  - group: common

stages:
  - template: pipelines/templates/validate.yml@templates
    parameters:
      aksServiceName: 'internal-portal'

外部Portal管道

外部门户管道的建议实施:

trigger: none

pool:
  vmImage: 'ubuntu-latest'

resources:
  repositories:
    - repository: templates
      type: git
      name: aks-templates/common-templates
      ref: refs/heads/main
    - repository: overlays
      type: git
      name: aks-microservices/overlays-and-services
      ref: refs/heads/main

    # Required? 
    # Can be removed if this pipeline is located in the same repository 
    # - repository: external-portal
    #   type: git
    #   name: aks-microservices/ExternalPortal
    #   ref: ${{ variables['Build.SourceBranch'] }}

variables:
  - group: common

stages:
  - template: pipelines/templates/validate.yml@templates
    parameters:
      aksServiceName: 'external-portal'
© www.soinside.com 2019 - 2024. All rights reserved.