GitLab Runner 在“dotnet restore”或“dotnet test”后停止

Posted

技术标签:

【中文标题】GitLab Runner 在“dotnet restore”或“dotnet test”后停止【英文标题】:GitLab Runner stopping after `dotnet restore` or `dotnet test` 【发布时间】:2021-01-12 15:57:35 【问题描述】:

我是 CI 新手,并尝试将以下 yaml 添加到我们的项目中。

图片:microsoft/dotnet:latest

stages:
  - test

test: 
  stage: test
  before_script:
    - 'echo Stage - Test started'
    - 'dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools'
  script:  
    - 'cd "./My Project"'  
    - 'dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"'
    - './tools/reportgenerator "-reports:./Tests/*/TestResults/*/coverage.cobertura.xml" "-targetdir:Reports_Coverage" -reportTypes:TextSummary'
    - 'cat ./Reports_Coverage/Summary.txt'
  after_script:
    - 'echo Stage - Test finished'

在工作中我得到以下输出:

Running with gitlab-runner 13.7.0 (943fc252) on ***
Resolving secrets
Preparing the "kubernetes" executor
Using Kubernetes namespace: gitlab-pipeline
Using Kubernetes executor with image microsoft/dotnet:latest ...
Preparing environment
Running on*** via ***...
Getting source from Git repository
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/***/.git/
Created fresh repository.
Checking out 07e98444 as ***...
Skipping Git submodules setup
Executing "step_script" stage of the job script
$ echo Stage - Test started
Stage - Test started
$ dotnet tool install dotnet-reportgenerator-globaltool --tool-path tools
You can invoke the tool using the following command: reportgenerator
Tool 'dotnet-reportgenerator-globaltool' (version '4.8.4') was successfully installed.
$ cd "./My Project"
$ dotnet test --settings:./Settings/CodeCoverage.runsettings --collect:"XPlat Code Coverage"
Running after_script
Running after script...
$ echo Stage - Test finished
Stage - Test finished
Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1

我稍微修改了一下,意识到这个缩小的 yaml 也失败了:

image: microsoft/dotnet:latest

stages:
  - test

test: 
  stage: test
  before_script:
    - 'cd "./My Project"'  
    - 'dotnet restore'
  script:  
    - 'dotnet test --no-restore'

这会产生一个相等的输出,除了它停在dotnet restore。 老实说,我不知道该怎么做,因为这是我发现的最精简的测试版本。 是我在项目中搞砸了什么,还是 GitLab Runner 本身的问题?

项目版本:.net Core App 3.1

【问题讨论】:

作为第一次测试,尝试使用名称中没有空格的文件夹。 文件夹中没有空格。为了简单起见,我只是在这里替换了它。正确的名称包含敏感数据。但您可以假设文件夹如下所示:“./superFancyProjectName”。 好吧,您的完整示例和缩小示例都使用cd "./My Project",这看起来可能是导致问题的原因。如果您的示例没有反映您的实际设置,则很难提供帮助。 【参考方案1】:

不是真正的解决方案,但我发现了这背后的问题。您可以设置 dotnet test 命令 (documentation) 的详细级别。这样做时,我发现您显然无法在基于 Linux 的 GitLab Runner 中运行 WPF 项目。

【讨论】:

以上是关于GitLab Runner 在“dotnet restore”或“dotnet test”后停止的主要内容,如果未能解决你的问题,请参考以下文章

gitlab runner 权限问题

为啥gitlab-runner执行完script停不下来?

gitlab gitlab runner

Gitlab CI/CD Runner

Gitlab-runner 未能删除权限被拒绝

gitlab-runner安装