Azure 管道模板中的动态变量
Dynamic Variables in Azure Pipeline Template
我正在开发一个模板来帮助简化我们对本地 IIS 服务器的部署。用户名和密码存储在 Azure Key Vault 中,但是当我去 Web App Management Task 中使用它们时,我无法访问它们。我在想我只是语法错误。
为了获取 Azure Key Vault 中的密钥,我正在使用以下任务。之所以有效,是因为它找到了密钥并且没有给我错误。
- task: AzureKeyVault@1
inputs:
azureSubscription : '_MyServiceConnectionHere_'
KeyVaultName : '_MyVaultNameHere_'
SecretsFilter : '${{ parameters.websiteName }}-AppPoolUsername,${{ parameters.websiteName }}-AppPoolPassword'
这就是我在 IIS Web 应用程序管理任务中使用它们的方式。 (我已将相关部分缩写为以下内容。)
- 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 }}
此处,用户名和密码未解析。如您所见,我正在尝试使用以下语法检索它们:
${{variables['${{parameters.websiteName}}-AppPoolUsername']}}
通过已组合的键名检索变量的正确语法是什么?
在 IISWebAppManagementOnMachineGroup 任务中,您只需使用 $(xxx)
获取一个变量作为普通变量。
${{}}
是编译时语法。您首先需要 运行 Azure Key Vault 任务才能在环境中生成变量。
要在以下任务中使用 Azure Key Vault 机密,只需使用 $(secret_name).
secret_name 是您在 Azure Key Vault 中创建的。
另请查看此博客中的详细示例:Using secrets from Azure Key Vault in a pipeline
我正在开发一个模板来帮助简化我们对本地 IIS 服务器的部署。用户名和密码存储在 Azure Key Vault 中,但是当我去 Web App Management Task 中使用它们时,我无法访问它们。我在想我只是语法错误。
为了获取 Azure Key Vault 中的密钥,我正在使用以下任务。之所以有效,是因为它找到了密钥并且没有给我错误。
- task: AzureKeyVault@1
inputs:
azureSubscription : '_MyServiceConnectionHere_'
KeyVaultName : '_MyVaultNameHere_'
SecretsFilter : '${{ parameters.websiteName }}-AppPoolUsername,${{ parameters.websiteName }}-AppPoolPassword'
这就是我在 IIS Web 应用程序管理任务中使用它们的方式。 (我已将相关部分缩写为以下内容。)
- 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 }}
此处,用户名和密码未解析。如您所见,我正在尝试使用以下语法检索它们:
${{variables['${{parameters.websiteName}}-AppPoolUsername']}}
通过已组合的键名检索变量的正确语法是什么?
在 IISWebAppManagementOnMachineGroup 任务中,您只需使用 $(xxx)
获取一个变量作为普通变量。
${{}}
是编译时语法。您首先需要 运行 Azure Key Vault 任务才能在环境中生成变量。
要在以下任务中使用 Azure Key Vault 机密,只需使用 $(secret_name).
secret_name 是您在 Azure Key Vault 中创建的。
另请查看此博客中的详细示例:Using secrets from Azure Key Vault in a pipeline