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


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


1.NUnit單元測試持續集成git

  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 "

【所有腳本】github

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.遇到的問題shell


2.1 一臺機子配置多個CI服務windows

原理就是用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版本便可解決gitlab

錯誤以下單元測試

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腳本 執行不成功的解決辦法

一、將PowerShell的腳本內容保存到一個.ps1爲後綴的文件中。
二、雙擊執行此ps1文件頗有可能沒法執行,提示:沒法加載文件 D:\PowerShell\test\myfirst1.ps1,由於在此係統中禁止執行腳本。
三、運行get-executionpolicy,若是結果是Restricted,那表示禁止執行腳本。
四、執行以下命令,下降系統的安全性,容許執行腳本:set-executionpolicy -executionpolicy unrestricted
 
 

2.5 亂碼問題

腳本加上這句能夠解決中文亂碼

Test:
script:
- chcp 65001
感謝 @Ellis_l

2.6 stuck問題

從新註冊一下便可,register

 

 

 

 

【參考資料】

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

TeamCity實戰(1):準備工做

相關文章
相關標籤/搜索