Adventures with Azure DevOps: .azcli Files to .sh

I am building a pipeline for deploying my application, the first thing I needed to do was deploy my Azure resources.

I have a tendency to be more imperative with my deployment strategy, using Azure PowerShell and Azure CLI over Azure Resource Management (ARM) templates.

I use Visual Studio Code to code my azure-pipelines.yml file, Azure Powershell, *.ps1, and Azure CLI, *.azcli files.

I use the .azcli file extension for the Visual Studio Code integration.

It seems though that the AzureCLI@2 task only wants to run files with an extension of .sh.

Fully qualified path of the script(.ps1 or .bat or .cmd when using Windows-based agent else .ps1 or .sh when using linux-based agent) or a path relative to the default working directory

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

Assuming my findings are correct, I think I am going to have to duplicate my .azcli files and assign the .sh extension.

I have a file called CreateResourceGroups.azcli that contains the following script:

az group create -n YOUR_RESOURCE_GROUP_NAME -l "YOUR_LOCATION"

I created another file, called CreateBashScripts.ps1, that contains the following:

Copy-Item -Path CreateResourceGroups.azcli -Destination CreateResourceGroups.sh

And then in my azure-pipelines.yml I have the following:

stages:
  - stage: ProvisionAzureResources
    jobs:
      - job: ProvisionAzureResources
        steps:
        - task: AzurePowerShell@5
          displayName: CreateBashFiles
          inputs:
            azureSubscription: 'YOUR_AZURE_SUBSCRIPTION_NAME'
            ScriptType: 'FilePath'
            ScriptPath: './CreateBashFiles.ps1'
            azurePowerShellVersion: 'LatestVersion'
        - task: AzureCLI@2
          displayName: CreateResourceGroups
          inputs:
            azureSubscription: 'azure.com_mattruma'
            scriptType: 'bash'
            scriptLocation: 'scriptPath'
            scriptPath: 'CreateResourceGroups.sh'

That seems to do the trick!

Now I get all the VS Code support for .azcli files and simply copy and rename them so Azure DevOps can run them.

If there is a better way, or I am totally missing something, please share!

Leave a Reply

Your email address will not be published.