我用变量board.subscription为我的各种环境定义了变量组,该变量指定了在WebApp部署中使用的Azure连接。
为部署作业引用这些变量组:
name: $(Date:yyyyMMdd)-$(Rev:r)
trigger:
- master
- dev
- feature/*
- bug/*
stages:
- stage: build
...
- stage: deploy_test
displayName: deploy to TEST
dependsOn: build
variables:
- group: 'Test-Deployment'
jobs:
- template: azure-pipelines/deploy.yml
parameters:
environment: TEST
- stage: deploy_prod
displayName: deploy to PROD
dependsOn: deploy_test
variables:
- group: 'Production-Deployment'
jobs:
- template: azure-pipelines/deploy.yml
parameters:
environment: PROD然后在deploy.yml文件中使用变量:
parameters:
environment: ''
agentImage: 'ubuntu-latest'
jobs:
- deployment: ${{ parameters.environment }}
displayName: deploy to ${{ parameters.environment }}
environment: ${{ parameters.environment }}
pool:
vmImage: ${{ parameters.agentImage }}
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: AzureWebApp@1
inputs:
azureSubscription: '$(board.subscription)'
appName: '$(board.functionapp)'但是,当在管道中排队时,似乎在填充变量之前对表达式进行计算,这将导致以下错误:
There was a resource authorization issue: "The pipeline is not valid. Job TEST: Step input azureSubscription references service connection $(board.subscription) which could not be found.当我为azureSubscription使用一个文字值时,它工作得很好。
问题:是否可以延迟此评估,或者是否有另一种方法可以避免在YAML文件中硬编码服务连接名称?
发布于 2020-03-30 10:06:03
我使用变量组进行了测试,得到了与您相同的错误:

如果订阅仅定义为yaml中的变量,然后在AzureWebApp任务中引用,则管道将不会收到此错误。
variables:
azureSubscription: connectionName
# -group : test1
stages:
...
- task: AzureWebApp@1
displayName: 'Azure Web App Deploy: 1123'
inputs:
azureSubscription: '$(azureSubscription)'
appType: webApp
appName: xxxhttps://stackoverflow.com/questions/60917078
复制相似问题