Deploying Azure Resource Manager (ARM) templates using Azure DevOps YAML pipeline is a multi-step process that can be broken down into the following steps:
- Create a new Azure DevOps project: If you haven’t already, create a new Azure DevOps project to host your pipeline.
- Create a YAML pipeline: Go to the “Pipelines” section of your Azure DevOps project and create a new pipeline. Select “Use the classic editor” and choose “Azure Resource Manager” as the template type.
- Add an Azure Resource Manager template task: In the pipeline, add an “Azure Resource Manager Template Deployment” task. This task will deploy the ARM template to your Azure subscription.
- Configure the task: In the task configuration, provide the path to your ARM template file and the path to your parameters file. Also, provide the subscription and resource group where you want to deploy the template.
- Add an Azure login task: In the pipeline, add an “Azure Login” task. This task will authenticate your pipeline with Azure so that it can deploy the template.
- Configure the task: In the task configuration, provide the service principal ID and password or the managed identity of the pipeline.
- Save and run the pipeline: Save the pipeline and run it. The pipeline will deploy the ARM template to your Azure subscription.
It is also possible to use the Azure CLI tasks or Azure PowerShell tasks to deploy the templates in the pipeline, or even use the Azure Resource Manager Deployment task with the
-Action parameter set to
CreateOrUpdate if you want to create or update the resources based on the template.
Additionally, you can also use the Azure DevOps Multi-stage pipeline feature to deploy the templates in different stages (like Dev, Test, Prod) and use variables to change the parameters values based on the stage.
It is important to ensure that the pipeline has the necessary permissions to deploy the templates and that the variables are securely stored in Azure DevOps.
The YAML file created in step 2 of the process to deploy Azure Resource Manager (ARM) templates using Azure DevOps would contain the pipeline definition, including the tasks and configurations required to deploy the template.
Here is an example of a YAML pipeline that deploys an ARM template to an Azure subscription:
# ARM template deployment pipeline pool: vmImage: 'windows-latest' steps: - task: AzureCLI@2 inputs: azureSubscription: 'your-subscription-name' scriptType: 'ps' scriptLocation: 'inlineScript' inlineScript: | az login --service-principal -u 'your-spn-app-id' -p 'your-spn-password' --tenant 'your-tenant-id' az account set --subscription 'your-subscription-id' az deployment group create -g 'your-resource-group' --template-file 'path/to/template.json' --parameters 'path/to/parameters.json' --verbose - task: AzurePowerShell@4 inputs: azureSubscription: 'your-subscription-name' ScriptType: 'FilePath' ScriptPath: 'path/to/deployment-script.ps1' ConnectedServiceName: 'your-subscription-name' pwsh: true - task: PublishBuildArtifacts@1 inputs: PathtoPublish: 'path/to/your-template-and-parameter-files' ArtifactName: 'ARM templates' publishLocation: 'Container'
This pipeline does the following:
- Authenticate to Azure using the Azure CLI task, using a service principal and tenant ID.
- Set the subscription using the Azure CLI task
- Run the command to create or update the resources based on the ARM template and parameters files, using the Azure CLI task.
- Authenticate to Azure using the Azure PowerShell task, using a service principal and tenant ID.
- Run the deployment-script.ps1, using the Azure PowerShell task.
- Publish the build artifacts, using the PublishBuildArtifacts task.