上一篇:《劈荆斩棘:Gitlab 部署 CI 持续集成

上一篇所配置的.gitlab-ci.yml

stages:
  - build
  - test

before_script:
  - echo "Restoring NuGet Packages..."
  - C:\NuGet\nuget.exe restore "src\CNBlogsCI-Sample.sln"
  only:
  - master

build_job:
  stage: build
  script:
  - echo "Release build..."
  - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "src\CNBlogsCI-Sample.sln"
  except:
  - tags
  only:
  - master

test_job:
  stage: test
  script:
  - echo "Tests run..."
  - C:\xunit.runner.console\tools\xunit.console.exe "src\ClassLibrary2\bin\debug\ClassLibrary2.dll"
  - C:\xunit.runner.console\tools\xunit.console.exe "src\ClassLibrary3\bin\debug\ClassLibrary3.dll"
  only:
  - master

有几个问题:

  • before_script要执行两次。
  • C:\NuGet\nuget.exe写死路径的写法不可取。
  • test_job需要上传debug中的dll文件。

对于上面的问题,完善如下:

stages:
  - build

build_job:
  stage: build
  script:
  - echo "Restoring NuGet Packages..."
  - nuget restore "src\CNBlogsCI-Sample.sln"
  - echo "Release build..."
  - msbuild /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "src\CNBlogsCI-Sample.sln"
  - echo "Tests run..."
  - xunit.console "src\ClassLibrary2\bin\debug\ClassLibrary2.dll"
  - xunit.console "src\ClassLibrary3\bin\debug\ClassLibrary3.dll"
  except:
  - tags
  only:
  - master

nugetmsbuildxunit.console命令都需要添加环境变量,为什么要去除before_scripttest_job?因为每执行一个jobgit都需要Fetching changes...,所以会清除不受git版本控制的文件。

还有就是,对于上面的第三个问题,因为msbuildRelease模式生成,而我们testdebug dll,所以就必须上传文件,我们把test中的debug改为Release就可以了。

我们可以把nugetmsbuildxunit.console独立出批命令实现。

restore.cmd

echo "NuGet Sources List..."
nuget Sources List
echo "Restoring NuGet Packages..."
nuget restore "src\CNBlogsCI-Sample.sln"

build.cmd

echo "Release build..."
msbuild /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "src\CNBlogsCI-Sample.sln"

test.cmd

echo "Tests run..."
xunit.console "src\ClassLibrary2\bin\Release\ClassLibrary2.dll"
xunit.console "src\ClassLibrary3\bin\Release\ClassLibrary3.dll"

.gitlab-ci.yml

stages:
  - build

build_job:
  stage: build
  script:
  - ./restore.cmd
  - ./build.cmd
  - ./test.cmd
  except:
  - tags

script中的cmd命令之前需要添加./

作者:田园里的蟋蟀
出处:http://www.cnblogs.com/xishuai/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

Leave a Reply

Your email address will not be published. Required fields are marked *