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.