Deploy Bicep with Azure DevOps

You can integrate Bicep files with Azure Pipelines for continuous integration and continuous deployment (CI/CD). In this article, you learn how to use an Azure CLI pipeline task to deploy a Bicep file.
Prepare your project
This article assumes your Bicep file and Azure DevOps organization are ready for creating the pipeline. The following steps show how to make sure you’re ready:
- Make sure you have an Azure DevOps organization.
- Make sure on DevOps organization, you’re an administrator of the Azure DevOps project that you will be using.
- A service connection is configured to your Azure subscription.
- Bicep file
/ Input parameters must be specified by the module consumer
param publicIpResourceName string ='samplepip'
param publicIpDnsLabel string = '${publicIpResourceName}-${newGuid()}'
param location string = resourceGroup().location
param dynamicAllocation bool = True
resource publicIp 'Microsoft.Network/publicIPAddresses@2020-06-01' = {
name: publicIpResourceName
location: location
properties: {
publicIPAllocationMethod: dynamicAllocation ? 'Dynamic' : 'Static'
dnsSettings: {
domainNameLabel: publicIpDnsLabel
}
}
}
// Set an output which can be accessed by the module consumer
output ipFqdn string = publicIp.properties.dnsSettings.fqdn
Create pipeline
- If you haven’t added a pipeline previously, you need to create a new pipeline. From your Azure DevOps organization, select Pipelines and New pipeline.
- Specify where your code is stored. The following image shows selecting Azure Repos Git or Gihub or any other availble source control options.
- From that source, select the repository that has the code for your project.
- Select the type of pipeline to create. You can select Starter pipeline.
You’re ready to either add an Azure PowerShell task or the copy file and deploy tasks.
Azure CLI task
The following YAML file creates a resource group and deploys a Bicep file by using an Azure CLI task:
trigger:
- master
name: Azway Bicep Deployment tutorial
variables:
vmImageName: 'ubuntu-latest'
azureServiceConnection: '<Service-connection-name>'
resourceGroupName: '<resource-group-name>'
location: '<your-resource-group-location>'
templateFile: './azuredeploy.bicep'
pool:
vmImage: $(vmImageName)
steps:
- task: AzureCLI@2
inputs:
azureSubscription: $(azureServiceConnection)
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
az --version
az group create --name $(resourceGroupName) --location $(location)
az deployment group create --resource-group $(resourceGroupName) --template-file $(templateFile)
An Azure CLI task takes the following inputs:
azureSubscription
, provide the name of the service connection that you created. See Prepare your project.scriptType
, use bash.scriptLocation
, use inlineScript, or scriptPath. If you specify scriptPath, you will also need to specify ascriptPath
parameter.inlineScript
, specify your script lines. The script provided in the sample builds a bicep file called azuredeploy.bicep and exists in the root of the repository.