0

I have set of unit test case and they are invoking a set of PowerShell commands. everything works fine on local machine but once pushed in to Azure pipelines, I get error as "New-CosmosDbContext is not recognized. Please check the spelling". It seems the Import command is not working when pushed to azure devops pipeline. Any idea as how we can fix this?

The lines what I am using is :

Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
    Start-CosmosDbEmulator    
    Get-CosmosDbEmulatorStatus
$cosmosDbContext = New-CosmosDbContext -Emulator
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54
  • @mklement0 if you can check this https://github.com/PlagueHO/CosmosDB it seems they are and I am able to run it locally. if I remove Import Module, it fails in very first command Start-CosmosDbEmulator – ZZZSharePoint Jun 28 '21 at 13:45

1 Answers1

0

As your follow-up question implies, you have since realized that two different modules are involved, and that you also need to import the third-party CosmosDB module in order to use its New-CosmosDbContext command:

  • Microsoft.Azure.CosmosDB.Emulator is the official Azure CosmosDB module.

  • CosmosDB is a third-party module.

    • Therefore, you need to first install the module (from the Powershell Gallery) - e.g., Install-Module CosmosDB -Scope CurrentUser - and then import it - ImportModule CosmosDB - before you can call New-CosmosDbContext
mklement0
  • 382,024
  • 64
  • 607
  • 775