5

我使用一个变量为我的各种环境定义了变量组,该变量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 文件中硬编码服务连接名称?

4

1 回答 1

0

我用变量组进行了测试,得到了和你一样的错误:

在此处输入图像描述

如果订阅只定义到 yaml 中的变量,然后在 AzureWebApp 任务中引用,则管道不会出现此错误。

variables:
  azureSubscription: connectionName
  # -group : test1

stages:
...
    - task: AzureWebApp@1
      displayName: 'Azure Web App Deploy: 1123'
      inputs:
        azureSubscription: '$(azureSubscription)'
        appType: webApp
        appName: xxx
于 2020-03-30T10:06:03.403 回答