在 ubuntu 18.04 docker 容器 azure pipeline 中运行 dotnet 测试,但是测试在托管代理的 ubuntu 版本中运行

问题描述 投票:0回答:1

我正在尝试在 Azure 管道中运行测试项目。我的项目使用 Azure cosmos 的 TestContainer 库,该库仅适用于 ubuntu 18.04,尽管该 VmImage 版本在 Azure 托管代理中已弃用。这就是为什么我在 ubuntu 18.04 docker 容器上运行它。

这是我的代码示例

  pool: 
    vmImage: ubuntu-20.04
  container:
    image: dthang42c3/rootuserubuntu18.04
    options: --user root --privileged
  steps:     
  - script: |
      sudo apt-get update
      sudo apt-get install -y libicu60
    displayName: 'Install libicu'
    
  - script: |
      sudo apt-get update
      sudo apt --assume-yes install wget
    displayName: 'Install wget'
    
  - script: |
      wget https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
      sudo dpkg -i packages-microsoft-prod.deb
      rm packages-microsoft-prod.deb
      sudo apt-get update
      sudo apt-get install -y dotnet-sdk-6.0
    displayName: 'Install .net'

  - script: |
      sudo apt-get update && sudo apt-get install -y lsb-release && sudo apt-get clean all
      lsb_release -a
    displayName: 'check version'
    
  - task: DotNetCoreCLI@2
    displayName: 'Restore BDD Tests'
    inputs:
      command: 'restore'
      projects: '**/MyTest.slnf'
      feedsToUse: config
      nugetConfigPath: 'nuget.config'

  - script: |
      dotnet test Domains/MyTest.csproj
    displayName: 'Run test'

在最后一步,当测试运行时,我注意到测试容器显示它在 Ubuntu 版本 20.04 的 VmImage 中运行。

但是它应该与 18.04 版本的 docker 容器一起运行。您可以看到“检查版本”步骤。清楚显示容器的版本是18.04

我该如何解决这个问题?任何人都可以帮忙吗?谢谢

.net azure-pipelines xunit docker-container testcontainers
1个回答
0
投票

这似乎是通过 docker-in-docker 运行测试时 Testcontainers 的一个已知问题。除 Azure DevOps 之外的其他 CI/CD 平台上也会出现此问题。

作为解决方法,您可以尝试在 Ubuntu 18.04 Docker 容器中设置以下环境变量。

TESTCONTAINERS_HOST_OVERRIDE=host.docker.internal

TESTCONTAINERS_HOST_OVERRIDE=localhost

相关文章和门票:


© www.soinside.com 2019 - 2024. All rights reserved.