[英]Build .NET solution using GitLab CI Pipeline
I have a solution with several .NET projects in it. 我有一个包含多个.NET项目的解决方案。 I use GitLab, not self-hosted, for version control and would like to start using their CI tools as well. 我使用GitLab(不是自托管的)进行版本控制,并且也希望开始使用其CI工具。 I have added the following .gitlab-ci.yml
file to my root: 我已将以下.gitlab-ci.yml
文件添加到我的根目录:
stages:
- build
- test
build_job:
stage: build
script:
- 'echo building...'
- 'msbuild.exe Bizio.sln'
except:
- tags
test_job:
stage: test
script:
- 'echo: testing...'
- 'msbuild.exe Bizio.sln'
- 'dir /s /b *.Tests.dll | findstr /r Tests\\bin\\ > tests_list.txt'
- 'for /f %%f in (tests_list.txt) do mstest.exe /testcontainer: "%%f"'
except:
- tags
The build
stage always fails because it doesn't know what msbuild
is. build
阶段总是失败,因为它不知道msbuild
是什么。 The exact error is: 确切的错误是:
/bin/bash: line 61: msbuild.exe: command not found / bin / bash:第61行:msbuild.exe:找不到命令
After some investigating, I've figured out that I'm using a shared runner. 经过一番调查,我发现我正在使用共享跑步程序。 Here is the entire output from the job run: 这是作业运行的全部输出:
Running with gitlab-runner 10.6.0-rc1 (0a9d5de9)
on docker-auto-scale 72989761
Using Docker executor with image ruby:2.5 ...
Pulling docker image ruby:2.5 ...
Using docker image sha256:bae0455cb2b9010f134a2da3a1fba9d217506beec2d41950d151e12a3112c418 for ruby:2.5 ...
Running on runner-72989761-project-1239128-concurrent-0 via runner-72989761-srm-1520985217-1a689f37...
Cloning repository...
Cloning into '/builds/hyjynx-studios/bizio'...
Checking out bc8085a4 as master...
Skipping Git submodules setup
$ echo building...
building...
$ C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe Bizio.sln
/bin/bash: line 61: msbuild.exe: command not found
ERROR: Job failed: exit code 1
It looks like the shared runner I have is using a Docker image for Ruby, which seems wrong. 看来我拥有的共享运行程序正在将Docker映像用于Ruby,这似乎是错误的。 I don't know how I can change that or select a different one that can be used for .NET. 我不知道如何更改该内容或选择可用于.NET的其他内容。 After some further investigating I'm getting worried that I'll have to jump through a lot of hoops to get what I want, like using an Azure VM to host a GitLab Runner that can build .NET apps. 经过进一步调查后,我担心我将不得不跳很多圈才能获得想要的东西,例如使用Azure VM托管可以构建.NET应用程序的GitLab Runner。
What do I need to do to use GitLab's CI pipelines to build my .NET solution using a non-self-hosted GitLab instance? 使用GitLab的CI管道使用非自托管的GitLab实例构建.NET解决方案,我需要做什么?
You should be able to setup your own shared runner on a machine with the Framework 4 build tools on it (either using a Docker image, like microsoft/dotnet-framework-build, or just your native machine). 您应该能够在装有Framework 4构建工具的机器上设置自己的共享运行器(使用Docker映像,例如microsoft / dotnet-framework-build,或者仅使用本机)。
The simplest case to get going is using your own desktop, where you know your solution already builds. 最简单的方法是使用您自己的桌面,您已经在其中建立了解决方案。 (Since using Docker images for the build is absolutely possible, but involves all of the extra steps of making sure you have docker working on your machine). (因为使用Docker镜像进行构建是绝对可能的,但是涉及确保您的计算机上使用Docker的所有额外步骤)。
Download gitlab-runner on your computer from https://docs.gitlab.com/runner/install/windows.html 从https://docs.gitlab.com/runner/install/windows.html将 gitlab-runner下载到您的计算机上
gitlab-runner register
键入gitlab-runner register
gitlab-runner install
在命令提示符下,键入gitlab-runner install
gitlab-runner start
然后输入gitlab-runner start
Whew. ew。 Now that runner is setup, it should be activated when you push a commit or a merge is requested. 现在已经设置好了运行器,当您推动提交或请求合并时,应该将其激活。
If you are having issues still with the .gitlab-ci.yml file building properly, you can debug it locally (without having to keep triggering it through gitlab.com) by going to your solution folder in the command line and then executing c:\\gitlab-runner\\gitlab-runner build
(To test the build step, for example). 如果您仍然无法正确构建.gitlab-ci.yml文件,可以通过在命令行中转到解决方案文件夹然后执行c:\\gitlab-runner\\gitlab-runner build
来在本地调试它(而不必通过gitlab.com不断触发它)。 c:\\gitlab-runner\\gitlab-runner build
(例如,测试构建步骤)。
If the build step has problem finding your solution file, you might want to try changing it from 'msbuild.exe Bizio.sln' to 'msbuild.exe .\\Bizio.sln' 如果生成步骤在查找解决方案文件时遇到问题,则可能需要尝试将其从“ msbuild.exe Bizio.sln”更改为“ msbuild.exe。\\ Bizio.sln”
To complement the answer by reallyrae, the other option for .Net Core apps is to include a call to the container as the first line in your .gitlab-ci.yml file. 为了通过realrae补充答案,.Net Core应用程序的另一个选项是在.gitlab-ci.yml文件的第一行中包含对容器的调用。 This will allow the build to happen on a shared GitLab.com runner. 这将允许在共享的GitLab.com运行程序上进行构建。
image: microsoft/dotnet
If you are building a traditional .Net application, you can try the mono docker image. 如果您要构建传统的.Net应用程序,则可以尝试使用mono docker映像。 If that doesn't work for you, the local runner is, as far as I know, your only option. 如果这对您不起作用,据我所知,本地跑步者是您唯一的选择。
image: mono:latest
Or multi stage builds: 或多阶段构建:
stages:
- build-dotnet
- test-dotnet
- build-mono
- test-mono
build-dotnet:
stage: build-dotnet
image: microsoft/dotnet:latest
before_script:
- "cd source"
- "dotnet restore"
- "cd .."
- "cd samples"
- "dotnet restore"
- "cd .."
script:
- "cd source"
- "dotnet build"
- "cd .."
- "cd samples"
- "dotnet build"
- "cd .."
build-mono:
stage: build-mono
image: mono:latest
before_script:
script:
- nuget restore ./source/Source.sln
- msbuild
/p:Configuration="Release"
/p:Platform="Any CPU"
"./source/Source.sln"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.