Skip to content

Commit 16957d9

Browse files
Merge pull request #120346 from Cadacious/users/scady/update-arm-template-deployment-doc
bicepparam usage in azure pipelines
2 parents 35b5949 + afed66c commit 16957d9

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

articles/azure-resource-manager/bicep/add-template-to-azure-pipelines.md

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
---
2-
title: CI/CD with Azure Pipelines and Bicep files
3-
description: In this quickstart, you learn how to configure continuous integration in Azure Pipelines by using Bicep files. It shows how to use an Azure CLI task to deploy a Bicep file.
2+
title: CI/CD with Azure Pipelines, Bicep, and bicepparam files
3+
description: In this quickstart, you learn how to configure continuous integration in Azure Pipelines by using Bicep and bicepparam files. It shows how to use an Azure CLI task to deploy a bicepparam file.
44
ms.topic: quickstart
55
ms.custom: devx-track-bicep, devx-track-azurecli
6-
ms.date: 06/21/2023
6+
ms.date: 02/29/2024
77
---
88

99
# Quickstart: Integrate Bicep with Azure Pipelines
@@ -22,6 +22,8 @@ You need to have configured a [service connection](/azure/devops/pipelines/libra
2222

2323
You need a [Bicep file](./quickstart-create-bicep-use-visual-studio-code.md) that defines the infrastructure for your project. This file is in a repository.
2424

25+
You need a [bicepparam file](/azure/azure-resource-manager/bicep/parameter-files) that defines the parameters used by your bicep file. This file is in a repository.
26+
2527
## Create pipeline
2628

2729
1. From your Azure DevOps organization, select **Pipelines** and **Create pipeline**.
@@ -47,88 +49,101 @@ You can use Azure Resource Group Deployment task or Azure CLI task to deploy a B
4749
### Use Azure Resource Manager Template Deployment task
4850

4951
> [!NOTE]
50-
> *AzureResourceManagerTemplateDeployment@3* task won't work if you have a *bicepparam* file.
52+
> As of version 3.235.0 of the [Azure Resource Manager Template Deployment task](/azure/devops/pipelines/tasks/reference/azure-resource-manager-template-deployment-v3), usage of [bicepparam](/azure/azure-resource-manager/bicep/parameter-files) files is supported.
53+
54+
> [!NOTE]
55+
> The `AzureResourceManagerTemplateDeployment@3` task requires both Bicep and bicepparam files be provided when using bicepparam. The Bicep file can reference all supported locations for module references. The bicepparam file must reference the local Bicep file in the `using` statement.
5156
52-
1. Replace your starter pipeline with the following YAML. It creates a resource group and deploys a Bicep file by using an [Azure Resource Manager Template Deployment task](/azure/devops/pipelines/tasks/reference/azure-resource-manager-template-deployment-v3).
57+
1. Replace your starter pipeline with the following YAML. It creates a resource group and deploys a Bicep and bicepparam file by using the Azure Resource Manager Template Deployment task.
5358

5459
```yml
5560
trigger:
5661
- main
5762

5863
name: Deploy Bicep files
5964

65+
parameters:
66+
azureServiceConnection: '<your-connection-name>'
67+
6068
variables:
6169
vmImageName: 'ubuntu-latest'
62-
63-
azureServiceConnection: '<your-connection-name>'
6470
resourceGroupName: 'exampleRG'
6571
location: '<your-resource-group-location>'
6672
templateFile: './main.bicep'
73+
csmParametersFile: './main.bicepparam'
74+
6775
pool:
6876
vmImage: $(vmImageName)
6977

7078
steps:
7179
- task: AzureResourceManagerTemplateDeployment@3
7280
inputs:
7381
deploymentScope: 'Resource Group'
74-
azureResourceManagerConnection: '$(azureServiceConnection)'
82+
azureSubscription: '${{ parameters.azureServiceConnection }}'
7583
action: 'Create Or Update Resource Group'
7684
resourceGroupName: '$(resourceGroupName)'
7785
location: '$(location)'
7886
templateLocation: 'Linked artifact'
7987
csmFile: '$(templateFile)'
88+
csmParametersFile: '$(csmParametersFile)'
8089
overrideParameters: '-storageAccountType Standard_LRS'
8190
deploymentMode: 'Incremental'
8291
deploymentName: 'DeployPipelineTemplate'
8392
```
8493
8594
1. Update the values of `azureServiceConnection` and `location`.
86-
1. Verify you have a `main.bicep` in your repo, and the content of the Bicep file.
95+
1. Verify you have a valid `main.bicep` file in your repo.
96+
1. Verify you have a valid `main.bicepparam` file in your repo that contains a [using](/azure/azure-resource-manager/bicep/bicep-using) statement.
8797
1. Select **Save**. The build pipeline automatically runs. Go back to the summary for your build pipeline, and watch the status.
8898

8999
### Use Azure CLI task
90100

91-
1. Replace your starter pipeline with the following YAML. It creates a resource group and deploys a Bicep file by using an [Azure CLI task](/azure/devops/pipelines/tasks/reference/azure-cli-v2):
101+
> [!NOTE]
102+
> The [az deployment group create](/cli/azure/deployment/group?view=azure-cli-latest#az-deployment-group-create&preserve-view=true) command requires only a bicepparam file. The `using` statement in the bicepparam file can target any supported location to reference the Bicep file. A Bicep file is only required in your repository when `using` from a local disk path with Azure CLI.
103+
104+
> [!NOTE]
105+
> When you use a *[bicepparam](/azure/azure-resource-manager/bicep/parameter-files)* file with the [az deployment group create](/cli/azure/deployment/group?view=azure-cli-latest#az-deployment-group-create&preserve-view=true) command, you can't override parameters.
106+
107+
1. Replace your starter pipeline with the following YAML. It creates a resource group and deploys a [bicepparam](/azure/azure-resource-manager/bicep/parameter-files) file by using an [Azure CLI task](/azure/devops/pipelines/tasks/reference/azure-cli-v2):
92108

93109
```yml
94110
trigger:
95111
- main
96112
97113
name: Deploy Bicep files
98114
115+
parameters:
116+
azureServiceConnection: '<your-connection-name>'
117+
99118
variables:
100119
vmImageName: 'ubuntu-latest'
101-
102-
azureServiceConnection: '<your-connection-name>'
103120
resourceGroupName: 'exampleRG'
104121
location: '<your-resource-group-location>'
105-
templateFile: 'main.bicep'
122+
bicepParamFile: './main.bicepparam'
123+
106124
pool:
107125
vmImage: $(vmImageName)
108126
109127
steps:
110128
- task: AzureCLI@2
111129
inputs:
112-
azureSubscription: $(azureServiceConnection)
130+
azureSubscription: '${{ parameters.azureServiceConnection }}'
113131
scriptType: bash
114132
scriptLocation: inlineScript
115133
useGlobalConfig: false
116134
inlineScript: |
117135
az --version
118136
az group create --name $(resourceGroupName) --location $(location)
119-
az deployment group create --resource-group $(resourceGroupName) --template-file $(templateFile)
120-
```
121-
122-
To override the parameters, update the last line of `inlineScript` to:
123-
124-
```bicep
125-
az deployment group create --resource-group $(resourceGroupName) --template-file $(templateFile) --parameters storageAccountType='Standard_GRS' location='eastus'
137+
az deployment group create `
138+
--resource-group $(resourceGroupName) `
139+
--parameters $(bicepParamFile) `
140+
--name DeployPipelineTemplate
126141
```
127142

128143
For the descriptions of the task inputs, see [Azure CLI task](/azure/devops/pipelines/tasks/reference/azure-cli-v2). When using the task on air-gapped cloud, you must set the `useGlobalConfig` property of the task to `true`. The default value is `false`.
129144

130145
1. Update the values of `azureServiceConnection` and `location`.
131-
1. Verify you have a `main.bicep` in your repo, and the content of the Bicep file.
146+
1. Verify you have a valid `main.bicepparam` file in your repo that contains a [using](/azure/azure-resource-manager/bicep/bicep-using) statement.
132147
1. Select **Save**. The build pipeline automatically runs. Go back to the summary for your build pipeline, and watch the status.
133148

134149
## Clean up resources

0 commit comments

Comments
 (0)