在我的发布管道中,我有两个变量 adminLogin 和 adminPassword 被标记为机密。我在同一个发布管道中有一个 Azure CLI@2 类型的任务。它是在 Ubuntu 代理上运行的内联 Powershell Core 脚本(我之前尝试过 windows 代理,但遇到了同样的问题)。目的是部署一个二头肌模板,将秘密变量 adminLogin 和 adminPassword 作为参数发送。
问题是我无法访问任务中的秘密变量。我尝试像这样直接访问它
Write-Host "##[warning]Using an input-macro works: $(adminLogin)"
但这没有用。我还尝试映射一个环境变量
#Your build pipeline references a secret variable named ‘adminLogin’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it secret. See https://go.microsoft.com/fwlink/?linkid=865972
variables:
resourceGroupName: '...'
environment: 'Test'
webSku: 'B1'
maxVCores: '1'
databaseName: '...'
applicationLogsRetentionInMB: '50'
databaseAutoTurnOffDelay: '60'
databaseMaxSizeInGiB: '10'
steps:
- task: AzureCLI@2
displayName: 'Deploy bicep template'
inputs:
azureSubscription: '....'
scriptType: pscore
scriptLocation: inlineScript
inlineScript: |
Write-Host "##[warning]Using an input-macro works: $(adminLogin)"
Write-Host "##[warning]Using the mapped env var for this task works and is recommended: $env:LOGIN"
az deployment group create `
--template-file $(System.DefaultWorkingDirectory)/..../deployment.bicep `
--resource-group $(resourceGroupName) `
--parameters '{ \"environment\":{ \"value\": \"$(environment)\"}, \"adminLogin\":{ \"value\": \"$env:LOGIN\"}, \"adminPassword\":{ \"value\": \"$env:PASSWORD\"}, \"webSku\":{ \"value\": \"$(webSku)\"}, \"maxVCores\":{ \"value\": $(maxVCores)}, \"databaseName\":{ \"value\": \"$(databaseName)\"}, \"applicationLogsRetentionInMB\":{ \"value\": $(applicationLogsRetentionInMB)}, \"databaseAutoTurnOffDelay\":{ \"value\": $(databaseAutoTurnOffDelay)}, \"databaseMaxSizeInGiB\":{ \"value\": $(databaseMaxSizeInGiB)}}'
env:
LOGIN: $(adminLogin)
PASSWORD: $(adminPassword)
部署二头肌模板时未发送 adminLogin 和 adminPassword,我收到此错误消息
{
"code": "DeploymentFailed",
"message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
"details": [
{
"code": "InvalidParameterValue",
"message": "Invalid value given for parameter Login. Specify a valid parameter value."
}
]
}
所以我有两个问题
- 如何更改我的 Azure CLI 任务以便它可以访问机密变量?
- 是否有其他方法可以从支持秘密变量的发布管道部署二头肌模板?