3 minute read

During Ignite Microsoft released bicep version 0.3.1. With this version the bicep language is not experimental any more. Some pointer about this version are:

  • Parity with ARM Templates
  • Integration with Azure CLI (v2.20.0+) and Azure PowerShell (v5.6.0+)
  • De-compiler
  • Supported by Microsoft

If you want to get started with bicep you can read my post about bicep I wrote a few months ago. When building ARM templates you may also want to start building the templates in the bicep language and execute the build within a automated pipelines to for example perform testing against the template with the ARM-TTK tooling.

Support

At the time of writing this post there is no default support for bicep in Azure DevOps. As mentioned above it is integrated within Azure CLI and Azure PowerShell but the CLI task and Azure PowerShell task in Azure DevOps do not already contain the latest version of the tool to support bicep.

Running bicep in a pipeline

So how do we run bicep then within a pipeline? To get started the tooling needs to be installed on the agent. As I normally use the Microsoft hosted agent the bicep tooling needs to be installed on each run as we do not have access to the agents.

This brings us to the first task for the pipeline that will perform the install. To install bicep the following bash code is used.

curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
chmod +x ./bicep
sudo mv ./bicep /usr/local/bin/bicep
bicep --help

The script it self needs to be performed on a Linux machine to install the bicep tooling and configure bicep into the PATH variable.

Doing this in a Azure DevOps Pipeline is very easy by using the bash task:

- bash: |
   curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
   chmod +x ./bicep
   sudo mv ./bicep /usr/local/bin/bicep
   bicep --help
   
  displayName: 'Install bicep'

With bicep installed the bicep commands can be executed. In my Pipelines a regularly do this in a separate task but the bash code could be added to the previous task as well.

- bash: |
   bicep build $(System.DefaultWorkingDirectory)/storage.bicep
   
  displayName: 'Build bicep file'

In the above task the bicep file in my repository is build and saved in the same location.

Completing the pipeline

With the possibility to build the bicep files in the pipeline the pipeline can be completed to copy the generated ARM templates to for example the pipeline artifacts location. These last steps are included in the sample pipeline shown below.

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- bash: |
   curl -Lo bicep https://github.com/Azure/bicep/releases/latest/download/bicep-linux-x64
   chmod +x ./bicep
   sudo mv ./bicep /usr/local/bin/bicep
   bicep --help
   
  displayName: 'Install bicep'

- bash: |
   bicep build $(System.DefaultWorkingDirectory)/storage.bicep
   
  displayName: 'Build bicep file'

- task: CopyFiles@2
  displayName: 'Copy Files to: $(build.artifactstagingdirectory)\arm'
  inputs:
    SourceFolder: '$(System.DefaultWorkingDirectory)'
    Contents: '*.json'
    TargetFolder: '$(build.artifactstagingdirectory)/arm'

- task: PublishPipelineArtifact@1
  inputs: