Matthew Goulart
Matthew Goulart

Reputation: 3065

GitLab Runner unable to restore nuget packages when started from gitlab but can when started locally

I am trying to get a .NET project to build and test using gitlab CI.

I have downloaded and installed the most recent version of the GitLab runner and successfully registered it with our gitlab instance. I have created the following .gitlab-ci.yaml file:

variables:
  Solution: Performance-Validation-Tool.sln

stages:
  - build
  - test
#  - deploy

build:
  stage: build
  script:
  - echo "Restoring NuGet packages..."
  - 'C:/nuget/NuGet.exe restore'
  - 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

The important part is the build action.

If I run a build from Gitlab itself I get the following error for ALL of the nugget packages:

WARNING: Unable to find version '3.5.0' of package 'NUnit.Console'.

  C:\Windows\system32\config\systemprofile\AppData\Local\NuGet\Cache: Package 'NUnit.Console.3.5.0' is not found on source 'C:\Windows\system32\config\systemprofile\AppData\Local\NuGet\Cache'.

  https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.

  An error occurred while sending the request.

  The remote name could not be resolved: 'api.nuget.org'

However if I run the following command LOCALLY:

C:\GitlabRunner\gitlab-ci-multi-runner-windows-amd64.exe exec shell build

everything works perfectly...

I have created firewall exceptions for both the gitlab runner and nugget.exe (I downloaded and installed the most recent version of nugget.exe)

The gitlab runner service is logged on as the same account I used to run the manual exec command.

I used the same nugget.exe for both the gitlab triggered builds and the manual exec command.

We are behind a corporate proxy, there is no HTTP_PROXY environment variable set. The proxy is configured in the "internet options". I did try to define the HTTP_PROXY setting for nugget.exe but later removed it after reading that nugget.exe uses the system proxy by default.

Thanks in advance for any help!

Upvotes: 2

Views: 9870

Answers (1)

Matthew Goulart
Matthew Goulart

Reputation: 3065

I happened to look at the service in the services list and noticed that although I had explicitly specified a user for the service, it was created with the "local system" account, which lacked the proxy settings, I assume. The service was corrected and it now builds properly.

Upvotes: 6

Related Questions