skip to Main Content

We use multi repo structure for our apps. e.g in the same azure devops project we have separate repos for services like internal or external portal etc.

I have created a multi stage pipeline that lives in a different repo called overlays separate from services like e.g internal or external portals but in the same project. It poses a challenge that when i run this pipeline it cant see branches that are present in other repos e.g. internal portal. work around is to move my pipeline in e.g. internal portal repo but this creates another challenge.

When we are deploying releases whether from main branch or testing them from feature branches then pipeline will error Could not get the latest source version for repository if the branch doesn’t exist e.g in external portal but present in internal portal.

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'

My question is: is there any way to create a parameter and populate it with list of existing branches from a remote repo to let user chose which one they want to deploy?

I have tried parameter of type "step" or "stepList" but not much luck.

2

Answers


  1. I’d suggest you to create a separate pipeline for the External and Internal portals.

    You’re already using a template (pipelines/templates/validate.yml@templates) so the code duplication will be minimal (e.g. duplicating some of the repository resources). But, on the other hand, you’ll be able to run each pipeline independently and using different branches.

    Internal Portal pipeline

    Suggested implementation for the Internal portal pipeline:

    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'
    

    External Portal pipeline

    Suggested implementation for the External Portal pipeline:

    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'
    
    Login or Signup to reply.
  2. You may try with the sample pipeline below, When the pipeline is run with the code from main branch of overlays repo, it sets ref: main for both ExternalPortal and InternalPortal repo resources; when the pipeline runs with the code from any other branch (feature) of overlays repo, it sets ref properties for both ExternalPortal and InternalPortal repo resources as the value you manually select from the picklists of the parameters.

    trigger: none
    
    pool:
      vmImage: 'ubuntu-latest'
    
    parameters:
    - name: branches_external_portal
      displayName: Select branch ref of ExternalPortal repo resource when not using code in main branch of overlays
      type: string
      default: main
      values:
      - main
      - externalbranch
    - name: branches_internal_portal
      displayName: Select branch ref of InternalPortal repo resource when not using code in main branch of overlays
      type: string
      default: main
      values:
      - main
      - Internalbranch
    
    
    variables:
    - ${{ if eq(variables['Build.SourceBranchName'], 'main') }}:
      - name: refExternal
        value: main
      - name: refInternal
        value: main
    - ${{ else }}:
      - name: refExternal
        value: ${{parameters.branches_external_portal}}
      - name: refInternal
        value: ${{parameters.branches_internal_portal}}
    
    resources:
      repositories:
      - repository: external-portal
        type: git
        name: aks-microservices/ExternalPortal
        ref: $(refExternal)
      - repository: internal-portal
        type: git
        name: aks-microservices/InternalPortal
        ref: $(refInternal)
    
    steps:
    - checkout: self
    - checkout: external-portal
    - checkout: internal-portal
    
    
    

    Image

    As of now, we have to explicitly specify the ref property of repository resources with template expressions like those conditional insertions (${{if}} and ${{else}}) under the variables node. See more details on Template Expressions in Repository Resource Definition.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search