在我的
azure-pipelines.yml
文件中,我无法通过二头肌文件进行部署并为其参数设置值。
这是我的二头肌文件的开始
targetScope = 'subscription'
param location string = 'uksouth'
param environmentCode string
这是我的
azure-pipelines.yml
文件中的任务
- task: AzureResourceManagerTemplateDeployment@3
inputs:
deploymentScope: 'Resource Group'
azureResourceManagerConnection: 'MyName(SomeGuid)'
subscriptionId: 'SomeGuid'
action: 'Create Or Update Resource Group'
resourceGroupName: '$(resourceGroupName)'
location: '$(location)'
templateLocation: 'Linked artifact'
csmFile: '$(Build.SourcesDirectory)/Infrastructure/Main.bicep'
deploymentMode: 'Incremental'
addSpnToEnvironment: true
useWithoutJSON: true
我尝试以 3 种不同的方式覆盖参数,但每种方式都出现错误
overrideParameters: 'location $(location) environmentCode $(environmentCode)'
##[error]One of the deployment parameters has an empty key. Please see https://aka.ms/arm-create-parameter-file for details.
overrideParameters: '-location $(location) -environmentCode $(environmentCode)'
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'The template resource 'resourceGroup' at line '1' and column '1182' is not valid: The language expression property 'location' doesn't exist, available properties are 'name, properties'.. Please see https://aka.ms/arm-functions for usage details.'.
overrideParameters: '--location $(location) --environmentCode $(environmentCode)'
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'The template parameters '-location, -environmentCode' in the parameters file are not valid; they are not present in the original template and can therefore not be provided at deployment time. The only supported parameters for this template are 'location, environmentCode'. Please see https://aka.ms/arm-pass-parameter-values for usage details.'.
AzureResourceManagerTemplateDeployment
任务用于使用ARM模板(ARM模板文件)而不是Bicep(Bicep文件)部署Azure资源。
要使用 Bicep 文件部署 Azure 资源,可以使用相关的 Azure CLI 命令或 Azure PowerShell cmdlet。在 Azure DevOps 的管道中,您可以使用
AzureCLI
任务来运行 Azure CLI 命令,或使用 AzurePowerShell
任务来运行 Azure PowerShell cmdlet。
要传递或覆盖 Bicep 文件中的参数:
如果使用 Azure CLI,您可以在命令上使用选项 '
--parameters
' 和 'KEY=VALUE
' 语法。例如。
az deployment group create \
--resource-group <resource-group-name> \
--template-file <path-to-bicep> \
--parameters location='$(location)' environmentCode='$(environmentCode)'
如果使用
AzurePowerShell
,您可以在 cmdlet 上使用“-KEY VALUE
”语法。例如。
New-AzResourceGroupDeployment `
-ResourceGroupName <resource-group-name> `
-TemplateFile <path-to-bicep> `
-location "$(location)" `
-environmentCode "$(environmentCode)"