Create Azure Infrastructure with Azure DevOps and Azure CLI Powershell scripts

In Azure DevOps, Pipelines can be used to create Azure infrastructure using Azure CLI and Powershell. This blog shows how to create a simple resource group in Azure using Azure DevOps Pipelines.

Create the Azure DevOps Pipeline

To get started, create a new Pipeline in your Azure DevOps project which references a git repository with the infrastructure scripts. You can use the Azure CLI button in the UI to create a new Azure CLI task. You need to choose Powershell core, if you are using an Linux image in the Pipeline. Select the Powershell script from your repository and Authorize the build to use the correct subscription.

The UI adds the following task to your yml file and saves the yml build configuration to the git repository when you click save.

- task: AzureCLI@2
  displayName: "Create resource group"
  inputs:
	azureSubscription: 'Visual Studio Enterprise(gggg...)'
	scriptType: 'pscore'
	scriptLocation: 'scriptPath'
	scriptPath: 'createKeyVaultExistingRG.ps1'

The file createKeyVaultExistingRG.ps1 is used in the build script. This Powershell file is pushed to the infrastructure repository. In the file, a simple az group create command from Azure CLI creates a new Azure resource group.

az group create -l westeurope -n "devops-rg"

When the build runs successfully, the Azure resource group has been created and can be viewed in the Azure portal.

The Powershell code can be completely run local on the development PC or as part of the build Pipeline. To run local, the local development machine must install the Azure CLI. Then the user can login using az login. Now the Powershell infrastructure script can be run, as long as the user has the permissions to create items in the Azure subscription.

Links:

https://dev.azure.com/

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-key-vault?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops

https://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/dotnet-core?view=azure-devops

2 comments

  1. […] Create Azure Infrastructure with Azure DevOps and Azure CLI Powershell scripts (Damien Bowden) […]

  2. […] Create Azure Infrastructure with Azure DevOps and Azure CLI Powershell scripts – Damien Bowden […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: