Bicep is a terser and more readable alternative language to ARM templates. Running ARM templates in Azure Pipelines is straightforward. However, there isn't yet a first class experience for running Bicep in Azure Pipelines. This post demonstrates an approach that can be used until a Bicep task is available.
If you've been working with Azure and infrastructure as code, you'll likely have encountered ARM templates. They're a domain specific language that lives inside JSON, used to define the infrastructure that is deployed to Azure; App Services, Key Vaults and the like.
Bicep is quite new, but already it enjoys feature parity with ARM templates (as of v0.3) and ships as part of the Azure CLI. However, as Bicep is new, it doesn't yet have a dedicated Azure Pipelines task for deployment. This should exist in future, perhaps as soon as the v0.4 release. In the meantime there's an alternative way to achieve this which we'll go through.
Let's take a simple Bicep file,
azuredeploy.bicep, which is designed to deploy an App Service resource to Azure. It looks like this:
When transpiled down to an ARM template, this Bicep file more than doubles in size:
azuredeploy.bicep- 1782 bytes
azuredeploy.json- 3863 bytes
This tells you something of the advantage of Bicep. The template comes with an associated
It's worth remembering that you can use the same parameters files with Bicep that you can use with ARM templates. This is great for minimising friction when it comes to migrating.
Now we have our Bicep file, we want to execute it from the context of an Azure Pipeline. If we were working directly with the ARM template we'd likely have something like this in place:
There's two tasks above. The first is the native task for ARM deployments which takes our ARM template and our parameters and deploys them. The second task takes the output variables from the first task and converts them into Azure Pipeline variables such that they can be referenced later in the pipeline. In this case this variablifies our
I'd recommend using the Azure CLI task to deploy. As long as that task is updated to Az CLI version 2.20 or later, it will automatically install the bicep CLI when calling
az deployment group create -f main.bicep.
Let's give it a go!
The above is just a single Azure CLI task (as advised). It invokes
az deployment group create passing the relevant parameters. It then acquires the output properties using
az deployment group show. Finally it once again converts these outputs to Azure Pipeline variables with some
This works right now, and running it results in something like the output below. So if you're excited about Bicep and don't want to wait for 0.4 to start moving on this, then this can get you going. To track the progress of the custom task, keep an eye on this issue.
There is even a simpler way to do this which I discovered subsequent to writing this. Have a read.