GitLab CI and MsBuild (with tests)

Jürgen Steinblock picture Jürgen Steinblock · Oct 6, 2015 · Viewed 21.4k times · Source

I am in the process of migrating my svn repsitories to git with GitLab.

Now I have seen that there is a continuous integration implementation with GitLab CI and just want to try it out.

I already installed and configured a Runner but Gitlab complains that I don't have a .gitlab-ci.yml file.

I already use TeamCity for continuous integration so I don't want to put too much effort into writing a build script.

Can anybody tell me where I can find a basic example of a gitlab-ci.yml file that basically just builds my Solution and runs all tests (MSTests)?

Answer

Jürgen Steinblock picture Jürgen Steinblock · Oct 7, 2015

Apparently there is no simple msbuild example but this should get you started:

variables:
  Solution: MySolution.sln

before_script:
  - "echo off"
  - 'call "%VS120COMNTOOLS%\vsvars32.bat"'
  # output environment variables (usefull for debugging, propably not what you want to do if your ci server is public)
  - echo.
  - set
  - echo.

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
  - echo building...
  - 'msbuild.exe "%Solution%"'
  except:
  - tags

test:
  stage: test
  script:
  - echo testing...
  - 'msbuild.exe "%Solution%"'
  - dir /s /b *.Tests.dll | findstr /r Tests\\*\\bin\\ > testcontainers.txt
  - 'for /f %%f in (testcontainers.txt) do mstest.exe /testcontainer:"%%f"'
  except:
  - tags

deploy:
  stage: deploy
  script:
  - echo deploying...
  - 'msbuild.exe "%Solution%" /t:publish'
  only:
  - production

Figuring out which tests to run is a bit tricky. My convention is that every project has a folder tests in which the test projects are named after the schema MyProject.Core.Tests (for a project called MyProject.Core)

Just as a first feedback towards gitlab-ci

I like the simplicity and the source control integration. But I would like to be able to modify the script before execution (especially while changing the script) but I could imaging to rerun a specific commit and inject variables or change the script (I can do that with teamcity). Or even ignore a failed test and rerun the script again (I do that a lot with teamcity). I know gitlab-ci does not know anything about my tests I just have a command line that returns an error code.