.NET Core dotnet restore failing on jenkins with S

2019-07-30 19:04发布

I'm trying to use the .NET Core CLI command dotnet restore on jenkins. When I log in as the user Jenkins uses, navigate to the workspace folder with the solution, it works. However when I create a Jenkins job and add a build step to execute a command, I get

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2, String path3)
   at NuGet.Common.NuGetEnvironment.GetFolderPath(NuGetFolderPath folder)
   at NuGet.Configuration.SettingsUtility.GetHttpCacheFolder()
   at NuGet.Configuration.NuGetPathContext.Create(ISettings settings)
   at Microsoft.DotNet.Configurer.NuGetCacheSentinel.get_NuGetCachePath()
   at Microsoft.DotNet.Configurer.NuGetCacheSentinel.Exists()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.ShouldPrimeNugetCache()
   at Microsoft.DotNet.Configurer.DotnetFirstTimeUseConfigurer.Configure()
   at Microsoft.DotNet.Cli.Program.ConfigureDotNetForFirstTimeUse(INuGetCacheSentinel nugetCacheSentinel)
   at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, ITelemetry telemetryClient)
   at Microsoft.DotNet.Cli.Program.Main(String[] args)

What's weird:

1) This fails the same way when I pass in the parameter "--packages C:\test" to dotnet restore.

2) The callstack indicates it thinks it is running and configuring .NET Core for the first time. This is despite having already run it as this user before.

3) I've read that by default dotnet restore restores packages to your %USERPROFILE% directory. Oddly, when I just get the jenkins task to ECHO %USERPROFILE%, it returns the C:\Users\Default directory, rather than the correct user directory. So it is not picking up the environment variable %USERPROFILE%.

Why does Jenkins think it is configuring .NET Core for the first time every time, why does it not have the correct user directory, and is there a way to work around these issues to run the .NET Core CLI?


Update: I delved into the nuget code and found it was trying to find LOCALAPPDATA. I set this in Jenkins but now I get the error

C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Value cannot be null. [D:\Workspaces\WEBCORE\WebStarter.sln] C:\Program Files\dotnet\sdk\1.0.4\NuGet.targets(97,5): error : Parameter name: path1 [D:\Workspaces\WEBCORE\WebStarter.sln]

Looks like a similar issue. What environment variables need to be set for dotnet restore to run?

1条回答
趁早两清
2楼-- · 2019-07-30 19:17

The same issue occurs on Bamboo Windows agents. The solution involved setting the following environment variables. Tested on dotnet core SDK v2.1.302.

    set HOMEPATH=%USERPROFILE%
    set APPDATA=%USERPROFILE%\AppData\Roaming
    set LOCALAPPDATA=%USERPROFILE%\AppData\Local
查看更多
登录 后发表回答