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):准备工作

posted @ 2016-08-16 17:42  傲翼飞寒  阅读(3173)  评论(0编辑  收藏  举报