如何在本地使用 gitlab-runner 测试 .NET 构建?
How to test .NET builds with gitlab-runner locally?
我正在尝试在本地为 .NET 项目测试我的 .gitlab-ci.yml
文件,但这样做时遇到了问题。为了能够在这里提出一个有用的问题,我尝试创建一个最小重现的说明,假设一台完全最新的 Windows 10 Pro 机器安装了 Visual Studio 2017。
- 在 Visual Studio 中的以下位置创建一个新的 .NET 4.6.2 控制台应用程序 "GlabTest":
c:\experiments\GlabTest
- 包管理器控制台:
Install-Package NewtonSoft.Json
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(1));
作为Main函数中唯一的一行代码
.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\'
.gitignore
这样:
.vs/
**/[Pp]ackages/*
[Bb]in/
[Oo]bj/
git init
和 git add .
和 git commit -m "Weeee"
- 关注these instructions并下载到
c:\gl\gitlab-runner-windows-amd64.exe
- 打开 PowerShell,转到
sln
文件夹
& 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job
这会吐出各种错误:
- "
Since gitLab Runner 10.0 this command is marked as DEPRECATED
" 没有任何关于如何从 exec
迁移的提示
- 正在将存储库克隆到其自身的子文件夹中 (
.../GlabTest/builds/0/project-0
)
- "
& was unexpected at this time.
"接近尾声
各种输出问题,例如最后一行是:
[31;1mERROR: Job failed: exit status 255
在深入研究 "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 尝试为输出着色的方式不兼容?
我正在尝试在本地为 .NET 项目测试我的 .gitlab-ci.yml
文件,但这样做时遇到了问题。为了能够在这里提出一个有用的问题,我尝试创建一个最小重现的说明,假设一台完全最新的 Windows 10 Pro 机器安装了 Visual Studio 2017。
- 在 Visual Studio 中的以下位置创建一个新的 .NET 4.6.2 控制台应用程序 "GlabTest":
c:\experiments\GlabTest
- 包管理器控制台:
Install-Package NewtonSoft.Json
Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(1));
作为Main函数中唯一的一行代码.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\'
.gitignore
这样:.vs/ **/[Pp]ackages/* [Bb]in/ [Oo]bj/
git init
和git add .
和git commit -m "Weeee"
- 关注these instructions并下载到
c:\gl\gitlab-runner-windows-amd64.exe
- 打开 PowerShell,转到
sln
文件夹 & 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job
这会吐出各种错误:
- "
Since gitLab Runner 10.0 this command is marked as DEPRECATED
" 没有任何关于如何从exec
迁移的提示
- 正在将存储库克隆到其自身的子文件夹中 (
.../GlabTest/builds/0/project-0
) - "
& was unexpected at this time.
"接近尾声 各种输出问题,例如最后一行是:
[31;1mERROR: Job failed: exit status 255
在深入研究 "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 尝试为输出着色的方式不兼容?