首页 > 解决方案 > GitLab - 找不到“单声道”主机

问题描述

嗨,我正在尝试在 GITLAB 中使用 CI/CD,我对此很陌生。

我能够创建以下 yml 文件

# Default image is docker:stable
image: docker:stable

# Define deployment stages
stages:
  - build   

# We use docker-in-docker (dind) for building docker images (build stage)
services:
  - docker:dind

# Build unit test on dotnet core sdk image  
build:
  stage: build
  image: mcr.microsoft.com/dotnet/sdk:5.0
  script:    
    - cd TestRegressionNebra/   
    - dotnet restore "TestRegressionNebra.csproj"
    - dotnet build "TestRegressionNebra.csproj"       
    - 'dotnet test "TestRegressionNebra.csproj" --test-adapter-path:. --logger:"junit;LogFilePath={assembly}-test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"'
  artifacts:
        when: always
        paths: 
            - ./**/*test-result.xml
        reports:
            junit: 
                - ./**/*test-result.xml    
  tags:
    - nebra

但是当我运行它时,它给了我这个错误:

测试运行 /builds/fm/ecommerce/qa/testregression/TestRegressionNebra/bin/Debug/net461/TestRegressionNebra.dll (.NETFramework,Version=v4.6.1) Microsoft (R) Test Execution Command Line Tool Version 16.11.0 开始测试执行,请稍候... 共有 1 个测试文件符合指定模式。System.IO.FileNotFoundException:找不到“单”主机。确保机器上安装了“mono”并且在 PATH 环境变量中可用。在 Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.DotnetHostHelper.GetMonoPath()

当我在我的个人电脑上运行相同的命令时,没有发现任何问题。

编辑:附上我的 *.csproj 文件

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
    <TargetFramework>net461</TargetFramework>

    <IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="JunitXml.TestLogger" Version="3.0.98" />
    <PackageReference Include="NUnit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
    <PackageReference Include="Selenium.Support" Version="3.141.0" />
    <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
    <PackageReference Include="Selenium.WebDriver.ChromeDriver" Version="94.0.4606.6100" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
    <ProjectReference Include="..\Common\Common.csproj" />
</ItemGroup>

<ItemGroup>
    <Reference Include="System.Configuration.Install" />
</ItemGroup>

标签: .netdockergitlab

解决方案


根据错误消息(和一些评论),您似乎使用了错误类型的跑步者。

GitLab CI/CD 在 GitLab Runner 上运行。如果你想运行任何依赖于 Windows 或 Windows 包的东西,那么你需要在 Windows 上安装 GitLab Runner,或者如果你正在使用 GitLab.com,则使用 Windows 共享运行器。

您在 CI yaml 中指定的映像image: mcr.microsoft.com/dotnet/sdk:5.0还需要安装所有依赖项,或者安装必要的依赖项作为该部分的script一部分。

我还建议查看dotnet CI 示例dotnet-core CI 示例。有关更多信息,请参阅CI/CD 示例文档页面


推荐阅读