首页 > 解决方案 > Azure Devops yaml 管道中 Azure cosmos Db 模拟器的任务失败

问题描述

我正在尝试使用 Azure Cosmos Db 模拟器测试我的单元测试用例。当我运行任务时,管道给了我错误,因为目标机器主动拒绝并且所有应该测试的查询都针对我的实际生产数据库运行。可能错误是管道无法连接到我的模拟器数据库。为了解决这个问题,我从任务列表中添加了 Azure Cosmos Db Emulator 任务(公共预览版),并在我的 YAMl 管道中添加了以下两个任务。我在任务运行 Azure Cosmos Db 模拟器的管道中收到以下错误:

来自守护进程的错误响应:未能在网络 nat 上创建端点 azure-cosmosdb-emulator:在 hnsCallRawResponse 期间失败:在 Win32 中 hnsCall 失败:该进程无法访问该文件,因为它正被另一个进程使用。(0x20) 错误:无法启动容器:11429cb294f98fe04cac2fbc8ff026063ee51d2dff4ece1bbeff33c778cdd4da

下面是我的 Yaml 脚本:

        - task: PowerShell@2
          inputs:
            targetType: 'inline'
            script: |
              Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
              Start-CosmosDbEmulator
              Get-Module
        - task: azure-cosmosdb.emulator-public-preview.run-cosmosdbemulatorcontainer.CosmosDbEmulator@2
          displayName: 'Run Azure Cosmos DB Emulator'

        - script: yarn test
          displayName: 'Run API tests (Cosmos DB)'
          env:
            HOST: $(CosmosDbEmulator.Endpoint)
            AUTH_KEY: C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==
            NODE_TLS_REJECT_UNAUTHORIZED: '0'

我在做什么错?如果有人可以解释。如果我不使用 Powershell 任务,则会收到以下错误:

来自守护进程的错误响应:hcsshim::CreateComputeSystem 120a874376d885ffea38a4e299f613340a599eae8a01b691366f21dcb6707501:容器操作系统与主机操作系统不匹配。

标签: azure-devopsazure-pipelines-yamlazure-cosmosdb-emulator

解决方案


推荐阅读