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
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 therepository
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:
External Portal pipeline
Suggested implementation for the External Portal pipeline:
You may try with the sample pipeline below, When the pipeline is run with the code from
main
branch ofoverlays
repo, it setsref: main
for bothExternalPortal
andInternalPortal
repo resources; when the pipeline runs with the code from any other branch (feature
) ofoverlays
repo, it setsref
properties for bothExternalPortal
andInternalPortal
repo resources as the value you manually select from the picklists of the parameters.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 thevariables
node. See more details on Template Expressions in Repository Resource Definition.