上篇文章介紹了GitLab CI的持續集成配置方法,本篇文章將主要介紹NUnit的持續集成和遇到的一些坑
1.NUnit單元測試持續集成
- 下載NUnit.3.4.1.msi,https://github.com/nunit/nunit/releases/tag/3.4.1
- 在持續集成的CI服務器上,安裝msi,並將安裝路徑從C:\Program Files (x86)改到C:\NUnit,因為shell腳本好像處理括號或者空格比較麻煩。
- 將之前的shell腳本的/p:Configuration=Release改成/p:Configuration=Debug
- 構建shell腳本命令
C:\NUnit\nunit-console\nunit3-console.exe " ConsoleApplication1 "【全部腳本】
stages: - build job: stage: build script: - echo "Restoring NuGet Packages..." - C:\test\nuget.exe restore "ConsoleApplication1.sln" - echo "Solution Build..." - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /p:Configuration=Debug /p:Platform="Any CPU" /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /verbosity:quiet "ConsoleApplication1.sln" - C:\NUnit\nunit-console\nunit3-console.exe " ConsoleApplication1.sln" tags: except: - tags
2.遇到的問題
2.1 一台機子配置多個CI服務
原理就是用sc命令創建一個gitlab_runner的服務,如下段代碼
sc create gitLab_FrameWork binPath= "D:\Kog_ECode\Kog_Framework\gitlab-ci-multi-runner-windows-amd64.exe run --working-directory D:\Kog_ECode\Kog_Framework --config D:\Kog_ECode\Kog_Framework\config.toml --service gitlab-runner --syslog"核心是BindPath,bindPath如何填寫,參考可以把gitlab-runner服務的搞進來,改個路徑即可
2.2 MSBuild 編譯錯誤
MSBuild間接引用會報錯,我直接安裝的vs2015,網上說安裝vs2015編譯工具和netframework的sdk版本即可解決
錯誤如下:
error CS0012: The type 'XXXXXXX' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.XXXXXX, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.Microsoft Build Tools 2015 下載地址 :
https://www.microsoft.com/en-in/download/details.aspx?id=48159
Microsoft Build Tools 2013 下載地址:
https://www.microsoft.com/en-gb/download/details.aspx?id=40760
2.3 MSB4019
CI服務器用msbuild命令編譯時候,會出現MBS4019(想看到錯誤編號,只要把命令/verbosity:quiet 改成/verbosity=diagnostic即可)
錯誤:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\XXXX.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.)【解決辦法】
1>安裝Microsoft Visual Studio 2015 Shell (獨立),Visual Studio 2015 Isolated Shell(需要有注冊Connect賬號)
2>把缺失的target拷貝上去,或者刪除
2.4 powershell腳本 執行不成功的解決辦法
1、將PowerShell的腳本內容保存到一個.ps1為后綴的文件中。
2、雙擊執行此ps1文件很有可能無法執行,提示:無法加載文件 D:\PowerShell\test\myfirst1.ps1,因為在此系統中禁止執行腳本。
3、運行get-executionpolicy,如果結果是Restricted,那表示禁止執行腳本。4、執行如下命令,降低系統的安全性,允許執行腳本:set-executionpolicy -executionpolicy unrestricted
【參考資料】