0

I am trying to create a context of Azure API management through scripts. The scripts I have I am able to execute the inbulit powershell terminal in Azure portal. But I am trying to run that scripts through my pipeline. currents pipeline runs under ubuntu, here is the yaml task. I have tried with enable core as well as without it.

steps:
- task: AzurePowerShell@5
  displayName: 'Azure PowerShell script: InlineScript'
  inputs:
    azureSubscription: '<sc>'
    ScriptType: InlineScript
    Inline: |
     Set-AzContext -SubscriptionId $(subId)
     $apimContext = New-AzureRmApiManagementContext -ResourceGroupName "$(rgName)" -ServiceName "$(serviceName)"

pipeline throws standard error -

The term 'New-AzureRmApiManagementContext' is not recognized
     | as a name of a cmdlet, function, script file, or executable
     | program. Check the spelling of the name, or if a path was
     | included, verify that the path is correct and try again.

Is there something I need to import while running this?

threeleggedrabbit
  • 1,722
  • 2
  • 28
  • 60

1 Answers1

1

The workaround, I can see there is a migration on the powershell happening https://learn.microsoft.com/en-us/powershell/azure/migrate-from-azurerm-to-az?view=azps-6.5.0.

So If I change that from New-AzureRmApiManagementContext to New-AzApiManagementContext in the pipeline it works.

threeleggedrabbit
  • 1,722
  • 2
  • 28
  • 60
  • Indeed, you should use the Az module, which is a replacement of AzureRM. If you want to upgrade your local environment, here is a link that can help you achieve that: https://learn.microsoft.com/en-us/powershell/azure/new-azureps-module-az?view=azps-6.5.0#upgrade-your-environment-to-az – Nadine Raiss Oct 25 '21 at 17:22