skip to Main Content

I am trying to execute the following yaml from a Windows 10 machine that has been configured as runner with Powershell as the shell. I have installed Azure CLI and Azure powershell modules on the windows machine. When I execute the pipeline, it runs the Azure CLI commands. However, the Azure powershell commands were not recognized. I am able to run these commands locally on the windows machine. Any idea what is missing here?

variables:
  DEFAULT_RG:
    description: "Default resource group to deploy the resources for testing"
    value: "newgrp"
  DEFAULT_LOCATION:
    description: "Default location of the testing resource group"
    value: "East US"
  
default:
  image: mcr.microsoft.com/azure-cli
  before_script:
    - az login --service-principal --username $SP_ID --password $SP_SECRET --tenant $TENANT_ID
    - az account set --subscription $SUBSCRIPTION_ID
    - set -euo pipefail

stages:
  - deploy
deploy automation account and tie it with UAMI:
  stage: deploy
   
  script:
    - New-AzAutomationAccount -Location $Location -Name $automationccount -ResourceGroupName $ResourceGroup
    - Set-AzAutomationAccount -ResourceGroupName $ResourceGroup -Name $automationccount -AssignUserIdentity "/subscriptions/$SUBSCRIPTION_ID/resourcegroups/$resourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$userAssignedOne"

2

Answers


  1. Chosen as BEST ANSWER

    Thanks for the response. Actually I removed the Azure-CLI image and tried a windows runner. I can confirm that it picked my windows runner where I had installed both Azure CLI and Azure powershell however the the runner couldn't recognize Azure Powershell commands. You may see the yaml below :

    build_deploy:
      stage: build_deploy
      script:
        - echo $SP_ID
        - echo $TENANT_ID
        - echo $SUBSCRIPTION_ID
        - az login --service-principal --username $SP_ID --password $SP_SECRET --tenant $TENANT_ID
        - az account set --subscription $SUBSCRIPTION_ID
        - set -euo pipefail
        - New-AzAutomationAccount -Location $Location -Name $automationccount -ResourceGroupName $ResourceGroup
        - Set-AzAutomationAccount -ResourceGroupName $ResourceGroup -Name $automationccount -AssignUserIdentity "/subscriptions/$SUBSCRIPTION_ID/resourcegroups/$resourceGroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/$userAssignedAcc"
    

  2. In your defaults, you’re using mcr.microsoft.com/azure-cli which is a Linux-based image. If you need to run Azure PowerShell commands you need to specify a windows runner. Since you are not specifying what runner to use explicitly in your deploy automation account and tie it with UAMI job, it’ll inherit from the default to use the Linux-based Docker image.

    You can either use Azure CLI equivalent for creating new automation accounts:

    or use a windows runner if you need to run the Azure PowerShell commands.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search