gpt4 book ai didi

azure - 如何将参数从 Azure DevOps 管道传递到 Bicep 模板

转载 作者:行者123 更新时间:2023-12-03 06:07:25 25 4
gpt4 key购买 nike

首先,二头肌对我来说是新的。我当前正在创建一个用于创建存储帐户的模板,并有一个我想要遵循的集合名称,其中包含环境名称。我想在 bicep 文件中添加一个参数/变量,以便在运行时从管道中获取值,因为环境名称是在运行时设置的,然后放入 Bicep 文件中,以便它创建一个存储帐户名称对于上述环境。

有人可以建议如何做到这一点吗?

谢谢

达伦

所以我当前的二头肌模板是这样的:

// Creates a storage account, private endpoints and DNS zones
@description('Azure region of the deployment')
param location string = 'UK South'

@description('Name of the storage account')
param storageName string = 'random${env}01'

@allowed([
'Standard_LRS'
'Standard_ZRS'
'Standard_GRS'
'Standard_GZRS'
'Standard_RAGRS'
'Standard_RAGZRS'
'Premium_LRS'
'Premium_ZRS'
])

@description('Storage SKU')
param storageSkuName string = 'Standard_LRS'

resource storage 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageName
location: location
tags: {
Environment: 'Dev'
}
sku: {
name: storageSkuName
}
kind: 'StorageV2'
properties: {
accessTier: 'Hot'
allowBlobPublicAccess: true
allowCrossTenantReplication: true
allowSharedKeyAccess: true
encryption: {
keySource: 'Microsoft.Storage'
requireInfrastructureEncryption: false
services: {
blob: {
enabled: true
keyType: 'Account'
}
file: {
enabled: true
keyType: 'Account'
}
queue: {
enabled: true
keyType: 'Service'
}
table: {
enabled: true
keyType: 'Service'
}
}
}
isHnsEnabled: false
isNfsV3Enabled: false
keyPolicy: {
keyExpirationPeriodInDays: 7
}
largeFileSharesState: 'Disabled'
minimumTlsVersion: 'TLS1_2'
networkAcls: {
bypass: 'AzureServices'
defaultAction: 'Allow'
}
supportsHttpsTrafficOnly: true
}
}

output storageId string = storage.id

最佳答案

首先,在您的管道中,您需要添加一个与您的环境相关的参数:

parameters:
- name: environment
displayName: "Your environment"
type: string

然后你需要将此参数添加到你的二头肌:

targetScope = 'resourceGroup'

// input parameters
param environment string

@description('Name of the storage account')
param storageName string = 'random${environment}01'

然后,您需要一个 Azure CLI 任务来启动二头肌部署并将参数传递给二头肌:

- task: AzureCLI@2
displayName: Bicep deployment
inputs:
azureSubscription: $(azureServiceConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
set -e

echo '##[Section]Deploy sa'

az deployment group create \
--resource-group $(rg_to_deploy_to) \
--name "sa-deployment" \
--template-file ./storageaccount.bicep \
--parameters environment="${{ parameters.environment }}"

请告诉我这是否可以解决您的问题。

关于azure - 如何将参数从 Azure DevOps 管道传递到 Bicep 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77181479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com