Deploy ARM template using Azure DevOps

·

4 min read

Cover Image for Deploy ARM template using Azure DevOps

Introduction

In this article, I will deploy ARM template using Azure Devops. I will use Continous Integration of ARM template with Azure Pipelines.

source code can be found on Source code and project info

Prepare your project

In This project we have ARM template and Azure DevOps organization ready for creating the pipeline. The following steps show how to make sure you're ready:

You have an Azure DevOps organization. If you don't have one, create one for free. If your team already has an Azure DevOps organization, make sure you're an administrator of the Azure DevOps project that you want to use.

Import GitHub repo to Azure Repos

You have an ARM template that defines the infrastructure for your project. I have ARM tepmate in the repo. the template will create storage account. Virtual Network, Public IP, NSG, subnet, NIC, VM.

Create Pipeline

I will add new pipeline

select Azure repos as repo

select the repo we just imported to Azure Repos Git in this project and then select starter pipeline below.

add two tasks to the pipeline. first one is copying files and second one is publish artifact. please find the code below.

Copy

Copy

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- main

pool:
  vmImage: ubuntu-latest

steps:
- script: echo Hello, world!
  displayName: 'Run a one-line script'

- script: |
    echo Add other tasks to build, test, and deploy your project.
    echo See https://aka.ms/yaml
  displayName: 'Run a multi-line script'
- task: CopyFiles@2
  inputs:
    SourceFolder: '$(agent.builddirectory)'
    Contents: '**'
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'storagedrop'
    publishLocation: 'Container'

now lets review the pipeline before we run

now lets save and run the pipleline

pipeline has run succesfully.

this pipeline has produced an atrifact. we will use this artifact to create resources mentioned in our template. In our ARM template we are creating a storage account.

let's create a release pipeline and use artifact we got from our build process.

for the release pipeline let's select empty job.

now let's add ARM template to the task

let's fill in the details so that resource get's created.

we need to integrate our build into the release pipeline. the artifact generated will be added.

I added artifact generated into the release pipeline.

now let's add task into the arm template added.

Let’s create the release

you can see that resource group is created and storage account is created. please see the logs image below.

I checked in Azure that new resource group is created and storage account is created.

I will add continous deployment and release to the pipeline

now we will add trigger to the release pipeline. this will make sure any changes to the repo will create the new build and will trigger to release pipeline. this will create new resources.

I will enable continoys deployment on the pipleline. when I make change to the repo the pipeline will get executed and resource will be created. Edit the release pipeline

click on the trigger that will let me enable continous deployment

enable create a new release when new build is available and enable pull trigger

Now save the settings. We have enabled continous deployment.

Now we will edit the repo. I will add more resources in the template. I will add storage account, public ip, Virtual network, subnet, NSG, NIC, Disk and Virtual machine.

commit the changes and you will see new bulild will be created and that will trigger release pipeline.

As we have enabled Continous Integration new release will be created

I will check in Azure and all the resources are created.

This is how you can deploy ARM template with Azure Devops. you can enabel contionus deployment to make sure when you add resource to the template they get created.