Scott
Scott

Reputation: 43

Dynamic Variables in Azure Pipeline Template

I am working on a template to help streamline our deployments to our on-premise IIS Servers. Usernames and passwords are stored in an Azure Key Vault, but when I go to use them in the Web App Management Task, I cannot access them. I am thinking I just have the syntax wrong.

To get the keys in the Azure Key Vault, I am using the following task. This works in that it finds the keys and doesn't give me an error.

- task: AzureKeyVault@1
  inputs:
    azureSubscription : '_MyServiceConnectionHere_'
    KeyVaultName : '_MyVaultNameHere_'
    SecretsFilter : '${{ parameters.websiteName }}-AppPoolUsername,${{ parameters.websiteName }}-AppPoolPassword'

This is how I am using them in the IIS Web App Manage Task. (I have abbreviated the following to the relevant parts.)

- task: IISWebAppManagementOnMachineGroup@0
  displayName: Update Website and App Pool
  inputs:
    AppPoolNameForWebsite: ${{ parameters.websiteName }}
    DotNetVersionForWebsite: 'No Managed Code'
    AppPoolIdentityForWebsite: 'specificUser'
    AppPoolUsernameForWebsite: ${{variables['${{parameters.websiteName}}-AppPoolUsername']}}
    AppPoolPasswordForWebsite: ${{variables['${{parameters.websiteName}}-AppPoolPassword']}}
    AppPoolName: ${{ parameters.websiteName }}

Here, the username and password don't resolve. As you can see, I am attempting to retrieve them using the following syntax:

${{variables['${{parameters.websiteName}}-AppPoolUsername']}}

What is the proper syntax for retrieving variables by a key name that has been composed?

Upvotes: 4

Views: 2567

Answers (1)

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51143

In IISWebAppManagementOnMachineGroup task, you just need to use $(xxx) to get a variable as normal variable.

${{}} is compile time syntax. You need first run Azure Key Vault task to make the variable generate in environment.

To use Azure Key Vault secrets in following tasks, simply use $(secret_name).

The secret_name is the one your created in Azure Key Vault.

Also take a look at detail samples in this blog: Using secrets from Azure Key Vault in a pipeline

Upvotes: 1

Related Questions