4
votes

I defined variable groups for my various environments with a variable board.subscription which specifies the Azure Service Connection to be used in WebApp deployment.

These variable groups are referenced for the deployment jobs:

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

and then the variable is used in the deploy.yml file:

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)'

However when queueing the pipeline, the expression seems to be evaluated before the variable is populated which leads to this error:

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.

When I use a literal value for azureSubscriptionit is working fine.

Question: Can this evaluation be delayed or is there another way for not having the Service Connection Name hardcoded in the YAML file?

1
I'm facing the same issue. How did you solve this?Eric Hansen
in the end I gave up and hard coded the azureSubscription value in the YML fileKai Walter

1 Answers

0
votes

I tested with variable group and got the same error as you:

enter image description here

If the subscription is only define to a variable in yaml and then referenced in the AzureWebApp task, the pipeline will not get this error.

variables:
  azureSubscription: connectionName
  # -group : test1

stages:
...
    - task: AzureWebApp@1
      displayName: 'Azure Web App Deploy: 1123'
      inputs:
        azureSubscription: '$(azureSubscription)'
        appType: webApp
        appName: xxx