我正在使用GitLab将我的svn repsitories迁移到git。
现在我已经看到有一个与GitLab CI的持续集成实现,只是想尝试一下。
我已经安装并配置了一个Runner,但Gitlab抱怨我没有.gitlab-ci.yml
文件。
我已经使用TeamCity进行持续集成,所以我不想花太多精力编写构建脚本。
任何人都可以告诉我在哪里可以找到一个gitlab-ci.yml
文件的基本示例,它基本上只是构建我的解决方案并运行所有测试(MSTests)?
显然没有简单的msbuild示例,但这应该让你开始:
variables:
Solution: MySolution.sln
before_script:
- "echo off"
- 'call "%VS120COMNTOOLS%\vsvars32.bat"'
# output environment variables (usefull for debugging, propably not what you want to do if your ci server is public)
- echo.
- set
- echo.
stages:
- build
- test
- deploy
build:
stage: build
script:
- echo building...
- 'msbuild.exe "%Solution%"'
except:
- tags
test:
stage: test
script:
- echo testing...
- 'msbuild.exe "%Solution%"'
- dir /s /b *.Tests.dll | findstr /r Tests\\*\\bin\\ > testcontainers.txt
- 'for /f %%f in (testcontainers.txt) do mstest.exe /testcontainer:"%%f"'
except:
- tags
deploy:
stage: deploy
script:
- echo deploying...
- 'msbuild.exe "%Solution%" /t:publish'
only:
- production
弄清楚要运行哪些测试有点棘手。我的惯例是每个项目都有一个文件夹测试,其中测试项目以模式MyProject.Core.Tests命名(对于一个名为MyProject.Core的项目)
就像对gitlab-ci的第一反馈一样
我喜欢简单和源代码控制集成。但我希望能够在执行之前修改脚本(特别是在更改脚本时),但我可以成像重新运行特定的提交并注入变量或更改脚本(我可以使用teamcity执行此操作)。或者甚至忽略失败的测试并再次重新运行脚本(我使用teamcity做了很多)。我知道gitlab-ci对我的测试一无所知我只有一个返回错误代码的命令行。
作为qazxsw poi的附录,我想为测试阶段脚本提出一个更简单的替代方案:
Jürgen Steinblock answer
这将对所有找到的测试项目二进制文件进行测试,这些二进制文件按照惯例在构建目录中使用variables:
SOLUTION_DIR: "MySolution"
BUILD_DIR: "Release"
TESTER: "vstest.console.exe" # or "mstest.exe /testcontainer:"
before_script:
- call "%VS120COMNTOOLS%\vsvars32" # import in path tools like msbuild, mstest, etc using VS script
test:
stage: test
script:
- for /f %%F in ('dir /s /b %SOLUTION_DIR%\%BUILD_DIR%\*Tests.dll') do set dllPath=%%F
- "%TESTER% %dllPath%"
结束。这具有不使用中间文件的优点。
这是我最终使用的。它在一次运行中运行所有* Tests.Dll。
*Tests.dll