GitLab CI持續集成配置方案(補)



上篇文章介紹了GitLab CI的持續集成配置方法,本篇文章將主要介紹NUnit的持續集成和遇到的一些坑


1.NUnit單元測試持續集成

  1. 下載NUnit.3.4.1.msihttps://github.com/nunit/nunit/releases/tag/3.4.1
  2. 在持續集成的CI服務器上,安裝msi,並將安裝路徑從C:\Program Files (x86)改到C:\NUnit,因為shell腳本好像處理括號或者空格比較麻煩。
  3. 將之前的shell腳本的/p:Configuration=Release改成/p:Configuration=Debug
  4. 構建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服務的搞進來,改個路徑即可

image

 

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.)

打開image033,引起錯誤的原因是這句話

image034

解決辦法

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
 
 

2.5 亂碼問題

腳本加上這句可以解決中文亂碼

Test:
script:
- chcp 65001
感謝 @Ellis_l

2.6 stuck問題

重新注冊一下即可,register

 

 

 

 

【參考資料】

使用roslyn代替MSBuild完成解決方案編譯

TeamCity實戰(1):准備工作


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM