Consider below code :
parameters:
- name: containerRegistry
displayName: Azure Container Registry Service Connection
type: string
default: 'acr-amaest'
values:
- acr-amaest
- name: deploymentSteps
type: stepList
default:
- script: echo "Add your deployment steps to your template"
displayName: Empty deployment step
- name: branchMapping
type: object
default:
develop: build
staging: staging
main: release
variables:
- name: environment
${{ each branch in parameters.branchMapping }}:
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/${{ branch.Key }}') }}:
value: ${{ branch.Value }}
stages:
- stage: Test
displayName: ???? Test
jobs:
- job:
steps:
# Printing empty string
- bash: |
echo ${{ variables['environment'] }}
# Works, prints everything
- ${{ each branch in parameters.branchMapping }}:
- bash: echo '${{ branch.Key }} -> ${{ branch.Value }} against ${{ variables['Build.SourceBranch'] }}'
# Prints nothing
- ${{ each branch in parameters.branchMapping }}:
- ${{ if eq(variables['Build.SourceBranchName'], '/${{ branch.Key }}') }}:
- bash: echo "Coucou ${{ branch.Key }}"
Could you please help ?