This question came from fact that you can only use global variables for deployment: https://docs.microsoft.com/en-us/azure/devops/pipelines/process/deployment-jobs?view=azure-devops#schema
Use only global level variables for defining a pool name. Stage/job level variables are not supported to define pool name.
But my config is a bit more complex. I do have main pipeline.yml with several stages. Stage's jobs defined in the template, so I have following structure:
# pipeline.yml (some cuts)
....
stages:
- stage: Build
displayName: Build all
jobs:
- template: ../templates/build.yml
parameters:
stage: 'DEV'
- stage: Dev
displayName: Deploy Dev
variables:
- group: GROUP-DEV
pool:
name: '$(env._global.agentPool)' # env._global.agentPool defined in in the variable group
jobs:
- template: ../templates/deployment.yml
parameters:
stage: 'DEV'
# other stages here ....
# templates/deployment.yml
parameters:
- name: stage
displayName: 'Stage'
type: string
jobs:
- deployment: Deploy${{ parameters.stage }}
displayName: Deploy ${{ parameters.stage }}
environment: ${{ parameters.stage }}
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: art_${{ parameters.stage }}
displayName: 'Download art_${{ parameters.stage }}'
# more steps here.....
Now the problem: with such config I got error:
##[error]Pipeline does not have permissions to use the referenced pool(s) . For authorization details, refer to https://aka.ms/yamlauthz.
which means we faced with limitation mentioned in the first quote (proof: https://developercommunity.visualstudio.com/t/pool-name-in-deployment-job-cannot-be-in-a-variabl/940174)
As soon as I change either pool name to hardcoded value or remove -deployment and use regular steps all works fine.
Question: with that, is there any chance to re-work templates to still use agent pool name from group variable? I need the -deployment task to reference environment.
What was tried already:
- use pool name as param of the templates/deployment.yml and use pool inside steps. No luck, same story