Jeroen
Jeroen

Reputation: 63699

How to test .NET builds with gitlab-runner locally?

I'm trying to test my .gitlab-ci.yml file for a .NET project locally, but am having trouble doing so. To be able to ask a useful question here I've tried to create instructions for a minimal repro, assuming a fully up to date Windows 10 Pro machine with Visual Studio 2017 installed.

  1. Create a new .NET 4.6.2 Console Application "GlabTest" in Visual Studio in the following location: c:\experiments\GlabTest
  2. Package Manager Console: Install-Package NewtonSoft.Json
  3. Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(1)); as the only line of code in the Main function
  4. .gitlab-ci.yml file next to the sln file with this content:

    variables:
      RELEASE_FOLDER: 'GlabTest/bin/Release'
      MSBUILD: 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe'
    
    stages:
      - build
    
    build_job:
      stage: build
      script:
        - 'nuget restore'
        - '& "$env:MSBUILD" GlabTest.sln /p:Configuration=Release /t:Rebuild'
      artifacts:
        paths:
          - '$env:RELEASE_FOLDER\'
    
  5. .gitignore with this:

    .vs/
    **/[Pp]ackages/*
    [Bb]in/
    [Oo]bj/
    
  6. git init and git add . and git commit -m "Weeee"

  7. Follow these instructions and download to c:\gl\gitlab-runner-windows-amd64.exe
  8. Open PowerShell, go to the sln folder
  9. & 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job

This will spit out all sorts of errors:

Before I dive deeper into a "DEPRECATED" command I should probably step back and ask: what is the recommended way to iterate locally a .gitlab-ci.yml file with Powershell build on a Windows machine?

Upvotes: 1

Views: 1510

Answers (1)

Jeroen
Jeroen

Reputation: 63699

[Why does it say DEPRECATED, what should we use instead?]

Well, there is not new way to do this, it seems exec is being deprecated without a current replacement.

Cloning the repo into a subfolder of itself ...

No clue yet how to fix this.

& was unexpected at this time

That's because cmd is the default shell on windows, so you should instead do:

& 'C:\gl\gitlab-runner-windows-amd64.exe' exec shell build_job --shell powershell

(Note the --shell powershell at the end.)

all sorts of output issues

No clue what's going on there. Possibly your terminal isn't compatible with the way gitlab-runner.exe is trying to colorize output?

Upvotes: 1

Related Questions