如何在本地使用 gitlab-runner 测试 .NET 构建?

How to test .NET builds with gitlab-runner locally?

我正在尝试在本地为 .NET 项目测试我的 .gitlab-ci.yml 文件,但这样做时遇到了问题。为了能够在这里提出一个有用的问题,我尝试创建一个最小重现的说明,假设一台完全最新的 Windows 10 Pro 机器安装了 Visual Studio 2017。

  1. 在 Visual Studio 中的以下位置创建一个新的 .NET 4.6.2 控制台应用程序 "GlabTest":c:\experiments\GlabTest
  2. 包管理器控制台:Install-Package NewtonSoft.Json
  3. Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(1));作为Main函数中唯一的一行代码
  4. .gitlab-ci.yml 文件位于具有以下内容的 sln 文件旁边:

    variables:
      RELEASE_FOLDER: 'GlabTest/bin/Release'
      MSBUILD: 'C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\MSBuild.exe'
    
    stages:
      - build
    
    build_job:
      stage: build
      script:
        - 'nuget restore'
        - '& "$env:MSBUILD" GlabTest.sln /p:Configuration=Release /t:Rebuild'
      artifacts:
        paths:
          - '$env:RELEASE_FOLDER\'
    
  5. .gitignore 这样:

    .vs/
    **/[Pp]ackages/*
    [Bb]in/
    [Oo]bj/
    
  6. git initgit add .git commit -m "Weeee"

  7. 关注these instructions并下载到c:\gl\gitlab-runner-windows-amd64.exe
  8. 打开 PowerShell,转到 sln 文件夹
  9. & 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job

这会吐出各种错误:

在深入研究 "DEPRECATED" 命令之前,我可能应该退后一步问:在 Windows 上使用 Powershell 构建本地迭代 .gitlab-ci.yml 文件的推荐方法是什么机器?

[Why does it say DEPRECATED, what should we use instead?]

嗯,这不是新方法it seems exec is being deprecated without a current replacement

Cloning the repo into a subfolder of itself ...

还不知道如何解决这个问题。

& was unexpected at this time

那是因为 cmd 是 windows 上的默认值 shell,所以您应该改为:

& 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job --shell powershell

(注意最后的--shell powershell。)

all sorts of output issues

不知道那里发生了什么。可能您的终端与 gitlab-runner.exe 尝试为输出着色的方式不兼容?