Reputation: 1114
My pipeline has a stage similar to this one
stages:
- stage: DeployToEnv
displayName: Deploy App
variables:
- group: Settings
- name: DOL.Environment
value: dev
jobs:
- template: ${{ parameters.postDeployJobTemplate }}
In my post-deploy template, I'd like to use a pool based on the environment, which is defined in the stage variables with variable DOL.Environment
I have tried:
1 - empty value
jobs:
- job: postDeployScriptStepsJob
displayName: Post Deploy Script Steps
pool:
${{ if eq(variables['DOL.Environment'], 'noprod') }}:
name: ${{parameters.poolNoProd}}
${{ if eq(variables['DOL.Environment'], 'prod') }}:
name: ${{parameters.poolProd}}
2 - syntax error
jobs:
- job: postDeployScriptStepsJob
displayName: Post Deploy Script Steps
pool:
- ${{ if eq('$(DOL.Environment)', 'noprod') }}:
name: ${{parameters.poolNoProd}}
- ${{ if eq('$(DOL.Environment)', 'prod') }}:
name: ${{parameters.poolProd}}
3 - variables not expected here
parameters:
- name: env
displayName: Environment
type: string
variables:
- ${{ if eq(parameters.env, 'noprod') }}:
- name: poolName
value: np
- ${{ if eq(parameters.env, 'prod') }}:
- name: poolName
value: pr
jobs:
- job: postDeployScriptStepsJob
displayName: Post Deploy Script Steps
pool:
name: $(poolName)
Unfortunately, since the stage is used by other teams too as part of another template, I cannot pass the pool name as a parameter however, I could pass the environment.
Upvotes: 1
Views: 2269
Reputation: 7251
You can pass the variables like below.
For example, you have 2 YAML files, one is YAML A and another is YAML B.
YAML A:
pool:
vmImage: 'windows-latest'
stages:
- stage: DeployToEnv
displayName: Deploy App
variables:
- name: test
value: noprod
- name: system.debug
value: true
jobs:
- template: azure-pipelines-1.yml
parameters:
test: ${{ variables.test }}
and YAML B:
parameters:
- name: test
type: string
jobs:
pool:
${{ if eq(parameters.test, 'noprod') }}:
name: VMAS2
${{ elseif eq(parameters.test, 'prod') }}:
name: VMAS
steps:
- script: echo ${{ parameters.test }}
On my side it works fine:
Upvotes: 1