2
votes

I have a .Net Core app which I am trying to get building on our new Jenkins server and am running into issues with restoring NuGet packages.

Our new build infrastructure consists of a Jenkins master running on CentOS, and this particular build is being run on a Windows Server 2012 slave. The connection between the two is through SSH via Cygwin.

This build works just fine on our old Jenkins, which has no build slaves, and runs on Windows Server 2012.

We are using a Jenkinsfile to call NAnt build targets to run the build. Here is the restore target from the NAnt build file:

<target name="restore_nuget_packages" description="Restores the NuGet packages for the solution" >
    <echo message="Restoring NuGet Packages" />
    <property name="USERPROFILE" value="${environment::get-variable('USERPROFILE')}" />
    <property name="HOME" value="${environment::get-variable('HOME')}" />
    <echo message="USERPROFILE is ${USERPROFILE}" />
    <echo message="HOME is ${HOME}" />
    <exec program="${dotnet_path}" commandline="restore ${projectName}.sln"></exec>
</target>

When this target runs on our new server, I get the following output:

[NuGet Restore] restore_nuget_packages:
[NuGet Restore] 
[NuGet Restore]      [echo] Restoring NuGet Packages
[NuGet Restore]      [echo] USERPROFILE is C:/Users/jenkinslvadmin
[NuGet Restore]      [echo] HOME is C:\Users\jenkinslvadmin
[NuGet Restore]      [exec]   Restoring packages for E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery\Microservice.NotificationDelivery.csproj...
[NuGet Restore]      [exec]   Restoring packages for E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery\Microservice.NotificationDelivery.csproj...
[NuGet Restore]      [exec]   Restoring packages for E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery.Tests\Microservice.NotificationDelivery.Tests.csproj...
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.VisualStudio.Web.CodeGeneration.Tools'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.VisualStudio.Web.CodeGeneration.Tools'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.NETCore.App'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.NETCore.App'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='jose-jwt'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='jose-jwt'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='AutoMapper'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='AutoMapper'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='MailKit'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='MailKit'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='AutoMapper.Extensions.Microsoft.DependencyInjection'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='AutoMapper.Extensions.Microsoft.DependencyInjection'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='FluentValidation.AspNetCore'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec] c:\program files\dotnet\sdk\2.1.301\NuGet.targets(114,5): error : Unable to load the service index for source https://api.nuget.org/v3/index.json. [E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery.sln]
[NuGet Restore]      [exec] c:\program files\dotnet\sdk\2.1.301\NuGet.targets(114,5): error :   Value cannot be null. [E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery.sln]
[NuGet Restore]      [exec] c:\program files\dotnet\sdk\2.1.301\NuGet.targets(114,5): error :   Parameter name: path1 [E:\Git\<some_company>.microservice.notificationdelivery\azure_build\azure_build\Microservice.NotificationDelivery.sln]
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='FluentValidation.AspNetCore'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.CodeAnalysis.CSharp.Workspaces'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.CodeAnalysis.CSharp.Workspaces'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.EntityFrameworkCore'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.EntityFrameworkCore'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.EntityFrameworkCore.SqlServer'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.EntityFrameworkCore.SqlServer'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.NET.Test.Sdk'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Microsoft.NET.Test.Sdk'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Moq'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='Moq'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='NUnit3TestAdapter'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='NUnit3TestAdapter'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.Contracts'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.Contracts'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.ServiceBus'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.ServiceBus'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.State'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore]      [exec]   Retrying 'FindPackagesByIdAsyncCore' for source 'https://proget.<some_company>.com/nuget/Microservice.Core/FindPackagesById()?id='<some_company>.Microservice.Core.State'&semVerLevel=2.0.0'.
[NuGet Restore]      [exec]   Value cannot be null.
[NuGet Restore]      [exec]   Parameter name: path1
[NuGet Restore] 
[NuGet Restore] BUILD FAILED

I have found these other, similar issues:

https://github.com/dotnet/core/issues/1037#issuecomment-338315953 https://blog.jongallant.com/2017/12/dotnet-value-cannot-be-null-parameter-name-path1/ https://github.com/dotnet/cli/issues/2385

They lead me to believe that it is an issue with the USERPROFILE or HOME variables being null, for Windows and Linux, respectively. dotnet uses these variables for its NuGet package cache, and that the Path.Combine() method is throwing the error when building the path to %USERPROFILE%.nuget\packages.

Suspecting that it might be an issue with the master running Linux and the slave running Windows, I tried setting both of these variables on the build node itself (I made sure to set USERPROFILE explicitly, even though it already should be defined), as well as in the build node environment variable configuration in the Jenkins UI. Alas, I am still getting the error. I even included some echos at the top of the target output, and as you can see, those variables are indeed set correctly, but the dotnet restore command is still throwing the error.

Any suggestions on what I might be missing?

1
Are you sure dotnet_path or projectName are not null? it doesn't seem dotnet is being called as that would at least echo its version number (or so I guess, I use Jenkins but via lua script, the log looks a bit different then). - Nick Otten
@NickOtten I made sure to verify those variables were defined, and that the output was indeed coming from dotnet. I got it solved though, I was focusing on the wrong environment variable (see my answer below). - cwadley

1 Answers

1
votes

I added -v diag to the dotnet call. While the output was VERY verbose, it didn't give much more information about the error (i.e. which variable was null), but I did get a stack trace, and some additional Googling led me to this:

.NET Core dotnet restore failing on jenkins with System.ArgumentNullException

I added the LOCALAPPDATA variable to the slave env variable configuration in the Jenkins UI, and that fixed it.

It appears that dotnet, and more specifically the nuget cli, relies on several Windows built-in environment variables for building paths, but I cannot find a list of these documented anywhere. Here is the current full list of custom variables that we have defined on our Jenkins slave:

  • APPDATA
  • LOCALAPPDATA
  • TEMP
  • USERPROFILE

This typically is not an issue, of course, since these should always exist on a Windows system, but when building on a Jenkins slave, it creates its own custom build environment, and you must explicitly define these required built-in variables yourself.