【问题标题】:Importing module command line in Azure Devops pipeline在 Azure Devops 管道中导入模块命令行
【发布时间】:2021-09-10 18:54:28
【问题描述】:

我有一组单元测试用例,它们正在调用一组 PowerShell 命令。在本地机器上一切正常,但一旦推送到 Azure 管道,我收到错误,因为“New-CosmosDbContext 无法识别。请检查拼写”。推送到 azure devops 管道时,导入命令似乎不起作用。知道如何解决这个问题吗?

我正在使用的行是:

Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
    Start-CosmosDbEmulator    
    Get-CosmosDbEmulatorStatus
$cosmosDbContext = New-CosmosDbContext -Emulator

【问题讨论】:

  • @mklement0 如果您可以检查此github.com/PlagueHO/CosmosDB,它们似乎是并且我可以在本地运行它。如果我删除导入模块,它会在第一个命令 Start-CosmosDbEmulator 中失败

标签: powershell azure-devops


【解决方案1】:

正如您的follow-up question 暗示的那样,您已经意识到涉及两个不同的模块,并且您需要导入第三方CosmosDB 模块为了使用它的New-CosmosDbContext 命令:

  • Microsoft.Azure.CosmosDB.Emulator官方 Azure CosmosDB 模块。

  • CosmosDB 是一个第三方模块。

    • 因此,您需要先安装模块(来自Powershell Gallery) - 例如,Install-Module CosmosDB -Scope CurrentUser - 然后导入它 - ImportModule CosmosDB - 然后才能调用 New-CosmosDbContext

【讨论】:

    猜你喜欢
    • 2020-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    相关资源
    最近更新 更多